可不可以一次性的向数据库中插入多条记录,

guxingwang 2005-03-08 08:13:29
可不可以一次性的向数据库中插入多条记录,
比如说我要向Table中的名为id的字段插入(1,2,3)这三条数据,其中(1,2,3)是用,

分隔开的id号的序列,应该为三条数据,这个怎么插入?
...全文
100 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xluzhong 2005-03-08
  • 打赏
  • 举报
回复
create table test(id int,[name] nvarchar(100) default 'ralph')
declare @id nvarchar(1000)
declare @s nvarchar(4000)

set @id='1,2,3'

set @s='insert into test(id) select '+replace(@id,',',' as id union all select ')+' select * from test'

exec(@s)

drop table test

xluzhong 2005-03-08
  • 打赏
  • 举报
回复
declare @id nvarchar(1000)
declare @s nvarchar(4000)

set @id='1,2,3'

set @s='select '+replace(@id,',',' as id union all select ')

exec(@s)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧