Sql简介 专题
专题目录
您的位置:database > Sql简介专题 > SQL插入多行
SQL插入多行
作者:--    发布时间:2019-11-20

很多时候开发人员都会问,是否可以在单个语句中将多行插入到一个表中。 目前,开发人员在表中插入值时必须编写多个insert语句。 它不仅枯燥乏味,而且耗时。 要摆脱这一点,应该尝试这种语法。 实际上,有三种不同的方法可以将多个值插入到单个表中。

  • 传统方法(简单插入)
  • sql insert select
  • sql server 2008+ 行构建

在sql server中插入多个值 -

create table student (id int value varchar (100));

sql insert :(传统插入)

insert into student (id, name)  
values (1, 'armaan');  
insert into student (id, name)  
values (2, 'billy');  
insert into student (id, name)  
values (3, 'charlie');

清理表:

truncate table student;

insert select :( select union insert)

insert into student (id, name)  
select 1, 'armaan'  
union all   
select 2, 'billy'  
union all  
select 3, 'charlie';

清理表:

truncate table student;

sql server 2008+行构建

insert into student (id, name)  
values (1, 'armaan'), (2, 'billy'), (3, 'charlie');

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册