一段用于清空数据库中所有的用户表的SQL语句
declare crsr insensitive cursor
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and [name] <> 'dtproperties' and [name]<> 'SpecialityInfo' and [name]<> 'ApplyRegInfo'--and crdate...
for read only
open crsr
declare @tblName sysname
fetch next from crsr into @tblName
while (@@fetch_status<>-1)
begin
EXEC('truncate table '+@tblName)
print('truncate table '+@tblName)
fetch next from crsr into @tblName
end
close crsr
for SELECT [name] FROM DBO.SYSOBJECTS
WHERE OBJECTPROPERTY(ID,N'IsTable')=1 and type = 'U' and [name] <> 'dtproperties' and [name]<> 'SpecialityInfo' and [name]<> 'ApplyRegInfo'--and crdate...
for read only
open crsr
declare @tblName sysname
fetch next from crsr into @tblName
while (@@fetch_status<>-1)
begin
EXEC('truncate table '+@tblName)
print('truncate table '+@tblName)
fetch next from crsr into @tblName
end
close crsr
deallocate crsr --删除以释放游标
浙公网安备 33010602011771号