SQL循环添加表中的字段
时间:2021-07-01 10:21:17
帮助过:3人阅读
USE BookDiscuss
DECLARE @num INT
DECLARE @numdiff INT
DECLARE @table VARCHAR(50)
DECLARE @sql VARCHAR(8000)
SET @numdiff=3
SET @num=0
WHILE @num<@numdiff
BEGIN
SET @table=‘DiscussPost_‘+CAST(@num AS VARCHAR(10));
SET @sql=
‘ALTER TABLE ‘+@table+‘ ADD PostFatherId INT DEFAULT 0;
ALTER TABLE ‘+@table+‘ ADD PostReplyUserId INT DEFAULT 0;‘
EXEC(@sql)
SET @num=@num+1
END
原地址:http://blog.sina.com.cn/s/blog_8bb128230102vpjy.html
SQL循环添加表中的字段
标签: