T-SQL批量添加指定记录3种方法

T-SQL批量添加指定记录3种方法

create table #s(id int identity(1,1) primary key,name nvarchar(20),age int)
--批量添加
insert into #s(name,age) values('stu1',20)
insert into #s(name,age) values('stu2',21)
insert into #s(name,age) values('stu3',22)
insert into #s(name,age) values('stu4',23)
insert into #s(name,age) values('stu5',24)
select * from #s
drop table #s

方法二:使用insert into...select...

create table #s(id int identity(1,1) primary key,name nvarchar(20),age int)
--批量添加
insert into #s(name,age) select 'stu1',20
insert into #s(name,age) select 'stu2',21
insert into #s(name,age) select 'stu3',22
insert into #s(name,age) select 'stu4',23
insert into #s(name,age) select 'stu5',24
select * from #s
drop table #s

方法三:使用insert into...select...union all...

create table #s(id int identity(1,1) primary key,name nvarchar(20),age int)
--批量添加
insert into #s(name,age) select 'stu1',20
union all select 'stu2',21
union all select 'stu3',22
union all select 'stu4',23
union all select 'stu5',24
select * from #s
drop table #s
posted @ 2010-09-28 11:33  Wind·e  阅读(456)  评论(1编辑  收藏  举报