木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2010-05-29 👁 5354 👍 0 💬 1 🔄 来源:本站原创
方法一:使用insert into...values...

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

评论(1)

shrek82 2010-05-30 01:41
刚学C#,今天在这里看到很多不错的学习资料,谢谢!😂
验证码
评论需审核通过后显示
← 上一篇 T-SQL生成随机记录 下一篇 → 从素数问题看对象思维方式