[sql] view plaincopyprint?
-------清空数据库所有表数据
exec sp_MSforeachtable "truncate table ?"
----查询数据库所有表名
select [name] from sysobjects where type='u'
--- 游标 清空所有表数据
declare @tableName varchar(50)
declare @Sql nvarchar(200)
declare @count int
declare TBCursor cursor for select [name] from sysobjects where type='u'
open TBCursor
fetch next from TBCursor into @tableName
while @@fetch_status=0
begin
set @Sql=N'delete from '+ @tableName
exec sp_executesql @Sql --过程 sp_executesql,第 1 行 过程需要类型为 'ntext/nchar/nvarchar' 的参数 '@statement'。
fetch next from TBCursor into @tableName
end
close TBCursor
deallocate TBCursor
-----向 IntKey 表 插入数据库表名
insert into IntKey(KeyName)
select [name] from sysobjects where type='u'
【SQLSERVER】清空数据库所有表数据
最新推荐文章于 2024-01-26 09:55:00 发布