SQL语句问题!

vikinlai 2003-11-28 05:50:04
如何在同一段SQL语句中,新增带有IDENTITY属性的多个表!
...全文
39 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cgsun 2003-11-28
  • 打赏
  • 举报
回复
declare @tablename varchar(100)
declare crs cursor for
select name from sysobjects where xtype='U'and name<>'dtproperties'
open crs

fetch next from crs into @tablename
while(@@fetch_status<>-1)
begin
exec ('alter table '+@tablename+' ADD [ID] INT identity(1,1)')
fetch next from crs into @tablename
end
close crs
deallocate crs
ropriest 2003-11-28
  • 打赏
  • 举报
回复
不管用什么方式,都只是一个一个的做的
cgsun 2003-11-28
  • 打赏
  • 举报
回复
用存储过程,用个表名变量
chinanewway 2003-11-28
  • 打赏
  • 举报
回复
看来只能用存储过程了,Try一Try吧!
MartinWang 2003-11-28
  • 打赏
  • 举报
回复
用存储过程吧,可以执行一系列语句:)
wzh1215 2003-11-28
  • 打赏
  • 举报
回复
只能一个表一个表的增了!
txlicenhe 2003-11-28
  • 打赏
  • 举报
回复
什么意思啊?

alter table table1 add id int identity(1,1)
alter table table2 add id int identity(1,1)
alter table table3 add id int identity(1,1)



34,874

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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