MSSQL数据库 插入多行数据的三种方法


创建表
create table #A(keyId int,info varchar(100))


方法一:

truncate table #A
go;

insert into #A(keyId,info)
values(1,’one’);
insert into #A(keyId,info)
values(2,’Two’);
insert into #A(keyId,info)
values(3,’three’);
go;
select keyId,info from #A
go;


方法二:

truncate table #A
go;

insert into #A(keyId,info)
select 1,’one’
union all
select 2,’Two’
union all
select 3,’three’
go;
select keyId,info from #A
go;


方法三:

truncate table #A
go;

insert into #A(keyId,info)
values(1,’one’),(2,’Two’),(3,’three’);
go;
select keyId,info from #A
go;