标签:语法 base default delete div try 效率 enter database
insert into 表名(列名1,列名2,...列名n) values(值1,值2,...值n);
1.列名和值要一一对应。
2.如果表名后,不定义列名,则默认给所有列添加值。
insert into 表名 values(值1,值2,...值n);
mysql> create table abc003(id int,name varchar(37),age int); --创建表 mysql> show tables; +------------------+ | Tables_in_abc001 | +------------------+ | ab001 | | abc003 | | abc004 | +------------------+ mysql> desc abc003; --查询表结构 +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(37) | YES | | NULL | | | age | int(11) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ mysql> insert into abc003 values(1,‘cai‘,18),(2,‘chuan‘,20),(3,‘qi‘,30); --增加列 mysql> select * from abc003; --查询列 +------+-------+------+ | id | name | age | +------+-------+------+ | 1 | cai | 18 | | 2 | chuan | 20 | | 3 | qi | 30 | +------+-------+------+
3.除了数字类型,其他类型需要使用引号(单双都可以)引起来
delete from 表名 [where 条件]
mysql> show tables; +------------------+ | Tables_in_abc001 | +------------------+ | abc003 | | abc004 | +------------------+ 2 rows in set (0.00 sec) mysql> desc abc003; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | int(11) | YES | | NULL | | | name | varchar(37) | YES | | NULL | | | age | int(11) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) mysql> select * from abc003; +------+-------+------+ | id | name | age | +------+-------+------+ | 1 | cai | 18 | | 2 | chuan | 20 | | 3 | qi | 30 | +------+-------+------+ 3 rows in set (0.00 sec) mysql> delete from abc003 where id=1; --删除列中的值 Query OK, 1 row affected (0.45 sec) mysql> select * from abc003; --查询列 +------+-------+------+ | id | name | age | +------+-------+------+ | 2 | chuan | 20 | | 3 | qi | 30 | +------+-------+------+
update 表名 set 列名1 = 值1,列名2 = 值2,...[where 条件];
mysql> update abc003 set age=99 where id=3; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 215 Current database: abc001 Query OK, 1 row affected (0.01 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from abc003; +------+-------+------+ | id | name | age | +------+-------+------+ | 2 | chuan | 20 | | 3 | qi | 99 | +------+-------+------+ 2 rows in set (0.00 sec)
注意:
标签:语法 base default delete div try 效率 enter database
原文地址:https://www.cnblogs.com/lspbk/p/14414022.html