SQLServer 清空某个库所有表
生活随笔
收集整理的這篇文章主要介紹了
SQLServer 清空某个库所有表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:SQLServer 清空某個庫所有表select @n=1
insert #temp(tablename) SELECT distinct sobjects.name
FROM sysobjects sobjects
WHERE sobjects.xtype = 'U'select @rows = @@rowcount
while @n <= @rows
begindeclare @tablename nvarchar(50)select @tablename = (select tablename from #temp where id = @n)--允許將顯式值插入表的標識列中 ON-允許 OFF-不允許--exec ('set identity_insert '+@tablename+' ON')--打開exec ('TRUNCATE TABLE '+@tablename)print(@tablename)select @n = @n + 1
end
go
與50位技術專家面對面20年技術見證,附贈技術全景圖
總結
以上是生活随笔為你收集整理的SQLServer 清空某个库所有表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【设计模式】前端必懂EventEmitt
- 下一篇: 突发热点事件下微博高可用注册中心vint