INSERT
表插入的语法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ({expr | DEFAULT},...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
或:
INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name
SET col_name={expr | DEFAULT}, ...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
或:
INSERT [LOW_PRIORITY | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
SELECT ...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
实验证明
如果列清单和VALUES清单均为空清单,则INSERT会创建一个行,每个列都被设置为默认值:
1
INSERT INTO tbl_name () VALUES();
假设worker表只有name和email,插入一条数据
1
INSERT INTO worker VALUES(“tom”,”tom@yahoo.com”);
批量插入多条数据
1
INSERT INTO worker VALUES(‘tom','tom@yahoo.com'),(‘paul','paul@yahoo.com');
给出要赋值的那个列,然后再列出值的插入数据
1
insert into worker (name) values ('tom');