Declare @vTableName sysname
Declare @i int
set @i = 0
Declare cr_table CURSOR --定义游标
FOR
select name from sysobjects where xtype = 'U' and uid =
(select uid from sysusers where name = 'Createnew') --
open cr_table
FETCH NEXT FROM cr_table INTO @vtablename //取游标数据到变量@vtablename
WHILE (@@FETCH_status = 0)
begin
set @i = @i + 1
set @vTableName = 'Createnew.'+@vTableName
print @vTableName
FETCH Next FROM cr_table INTO @VtableName //取游标数据到变量@vtablename
end
CLOSE Cr_table //关闭游标
select @i
DEALLOCATE Cr_Table --Removes a cursor reference. //释放游标