当前位置: 代码迷 >> Sql Server >> 怎么用查询分析器循环建表
  详细解决方案

怎么用查询分析器循环建表

热度:54   发布时间:2016-04-27 16:11:03.0
如何用查询分析器循环建表?
不知道表名如何定义
我用create   table   bbs '[email protected]+ '好象不行(刚开始学的,可能笑话了)

代码如下:


declare   @i   int
set   @i=3
while   @i <5
begin
create   table   bbs '[email protected]+ '
(
id   int,
title   varchar(100),
Content   varchar(8000)
)

create   table   report '[email protected]+ '
(
id   int,
topid   int,
Content   varchar(8000),
ip   varchar(15),
)
set   @[email protected]+1
end

------解决方案--------------------
declare @i int
declare @sql nvarchar(200)
set @i=3
while @i <5
begin
set @sql= 'create table bbs '+CONVERT(nvarchar(20),@i)+ '
(
id int,
title varchar(100),
Content varchar(8000)
)

create table report '+CONVERT(nvarchar(20),@i)+ '
(
id int,
topid int,
Content varchar(8000),
ip varchar(15),
) '
exec (@sql)
set @[email protected]+1
end
  相关解决方案