一 清空数据库里所有的表
复制代码 代码如下:
DECLARE @tablename varchar(50)
DECLARE @truncatesql varchar(255)
DECLARE TrCun_Cursor CURSOR FOR
select [name] from sysobjects where type = ‘U’
–有条件的清空表 name<>’不想清空的表名’–
OPEN TrCun_Cursor
FETCH TrCun_Cursor INTO
@tablename
WHILE(@@fetch_status = 0)
BEGIN
SET @truncatesql = ‘truncate table ‘ + @tablename
–exec(@truncatesql) –当要删除时,就去掉–
PRINT @truncatesql
FETCH TrCun_Cursor INTO @tablename
END
CLOSE TrCun_Cursor
DEALLOCATE TrCun_Cursor
二 清除数据库里的所有数据
EXEC sp_MSforeachtable “truncate table ?”
原创文章,作者:kirin,如若转载,请注明出处:https://blog.ytso.com/tech/database/233519.html