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

方法一:使用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


上一篇: T-SQL生成随机记录
下一篇: 从素数问题看对象思维方式
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
最新日志:
评论: 1 | 引用: 0 | 查看次数: 4825
shrek82[2010-05-30 01:41 AM | | | 125.95.99.48 | del | 回复回复]
沙发
刚学C#,今天在这里看到很多不错的学习资料,谢谢!
发表评论
登录后再发表评论!