[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】清空數據庫所有表數據
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.