清空数据库里所有的表 清除数据库里的所有数据
一 清空数据库里所有的表 代码如下:
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 ?"
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn