清除所有表数据
2011-04-02 16:05
239 查看
Declare @t table(query varchar(2000),tables varchar(100))
Insert into @t
select 'Truncate table ['+T.table_name+']', T.Table_Name from INFORMATION_SCHEMA.TABLES T
left outer join INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
on T.table_name=TC.table_name
where (TC.constraint_Type ='Foreign Key' or TC.constraint_Type is NULL) and
T.table_name not in ('dtproperties','sysconstraints','syssegments') and
Table_type='BASE TABLE'
Insert into @t
select 'delete from ['+T.table_name+']', T.Table_Name from INFORMATION_SCHEMA.TABLES T
left outer join INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
on T.table_name=TC.table_name where TC.constraint_Type ='Primary Key' and T.table_name <>'dtproperties'and Table_type='BASE TABLE'
Declare @sql varchar(8000)
Select @sql=IsNull(@sql+' ','')+ query from @t
print(@sql)
Exec(@sql)
Insert into @t
select 'Truncate table ['+T.table_name+']', T.Table_Name from INFORMATION_SCHEMA.TABLES T
left outer join INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
on T.table_name=TC.table_name
where (TC.constraint_Type ='Foreign Key' or TC.constraint_Type is NULL) and
T.table_name not in ('dtproperties','sysconstraints','syssegments') and
Table_type='BASE TABLE'
Insert into @t
select 'delete from ['+T.table_name+']', T.Table_Name from INFORMATION_SCHEMA.TABLES T
left outer join INFORMATION_SCHEMA.TABLE_CONSTRAINTS TC
on T.table_name=TC.table_name where TC.constraint_Type ='Primary Key' and T.table_name <>'dtproperties'and Table_type='BASE TABLE'
Declare @sql varchar(8000)
Select @sql=IsNull(@sql+' ','')+ query from @t
print(@sql)
Exec(@sql)
相关文章推荐
- MSSQL清除数据库中所有数据
- 在MSSQL中如何用SQL清除所有表的数据
- sqlite数据库在程序打包之前清除所有表中的数据
- MSSQL中如何用SQL清除所有表的数据(downmoon)?
- 清除数据库里面所有用户表的数据
- 清除userDefaults所有数据(Swift)
- Afinal数据库模块的实现准备(一)_清除所有数据表
- 清除数据库中表中的所有数据
- sql清除表中所有数据,留下表结构
- postgreSQL清除所有表 或 所有表中数据
- 清除数据的所有内容
- 亲测 小米5清除所有数据 包括指纹解锁和帐号图案解锁(此方法适用于所有Android手机)
- RabbitMQ如何在命令行下清除消息队列中的所有数据
- 一个MySQL清除数据库所有表数据保留表结构的存储过程
- easyui清除dategrid所有数据(模拟本地加载)
- MSSQL中如何用SQL清除所有表的数据(downmoon)?
- 关于清除android /data下所有数据的命令
- 反转一个字符串和删除N层级目录的所有文件或者删除数据库所有表保留数据库;清除数据库所有表的数据
- 转:清除所有表的数据
- sql server 清除数据库中所有表的数据