【SQLSERVER】清空数据库所有表数据
发布时间:2020-12-12 13:41:36 所属栏目:MsSql教程 来源:网络整理
导读:[sql] view plaincopyprint?-------清空数据库所有表数据 exec sp_MSforeachtable "truncate table ?" ----查询数据库所有表名 select [name] from sysobjects where type='u' --- 游标 清空所有表数据 declare @tableName varchar(50) declare @Sql nvarcha
[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' (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |