【SQL】 使用SQL语句在表中添加数据(一条 / 多条)

1.单条数据
insert into 表名(字段名1,字段名2)value(值1,值2);
例如:

insert into tablename(op_time,name,student_no,grade) value('2020-01-23', '张三 ','1','88');

2.多条数据
insert into 表名(字段名1,字段名2)values(值a1,值b1), (值a2,值b2);
例如:

insert into  tablename(op_time,name,student_no,grade) values ('2020-01-23', '张三 ','1','88'), ('2020-08-24', '李四','2','95');

3.从另外的一张表中读取多条数据添加到新表中

insert into tablename(col1,col2,col3)
select a,b,c from tableA;
#tableA:原表,tablename:新表

4.从其他的多张表中读取数据添加到新表中

insert into tablename(col1,col2,col3)
select a,b,c from tableA where a=1
union all
select a,b,c from tableB where a=2;

更多推荐

【SQL】 使用SQL语句在表中添加数据(一条 / 多条)