清空数据库:sp_MSforeachtable
2007-01-14 19:32
211 查看
删除所有表中的数据 :
sp_MSforeachtable @command1='Delete from ?' 或
sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"
?表示所有表
还有一个参数为@whereend, @whereend='name in 'table1','table2',... ...'
这个参数是限制此存储过程的操作用于哪些表.
1。在sql server2000下一个数据库中有建立了几十个表,现在要给每个表增加同样的列。可以用"alter table"语句,但是这么多表一个一个的操作太麻烦,有什么方法可以操作循环每一个表呢?
方法:sp_msforeachtable 'alter table ? add 列名 int'
2。假设所有表中的'note' 字段不能为空,如果为空则要改为"。
方法:sp_msforeachtable 'update ? set note='''' where note is null'
sp_MSforeachtable @command1='Delete from ?' 或
sp_MSforeachtable @command1 = "TRUNCATE TABLE ?"
?表示所有表
还有一个参数为@whereend, @whereend='name in 'table1','table2',... ...'
这个参数是限制此存储过程的操作用于哪些表.
1。在sql server2000下一个数据库中有建立了几十个表,现在要给每个表增加同样的列。可以用"alter table"语句,但是这么多表一个一个的操作太麻烦,有什么方法可以操作循环每一个表呢?
方法:sp_msforeachtable 'alter table ? add 列名 int'
2。假设所有表中的'note' 字段不能为空,如果为空则要改为"。
方法:sp_msforeachtable 'update ? set note='''' where note is null'
相关文章推荐
- sp_MSforeachtable的用法,对某数据库的所有表进行操作
- 用sp_MSforeachtable快速清除数据库表中的数据
- 删除数据库所有数据 附带sp_MSforeachtable使用方法
- 使用SP_MSForEachTable重建一个数据库中所有的索引
- 【推荐】(SqlServer)不公开存储过程sp_Msforeachtable与sp_Msforeachdb详解
- 禁用全部表的外键 sp_msforeachtable
- sp_MSforeachtable 与 sp_MSforeachdb
- 详解SQL Server的两个存储过程:sp_MSforeachtable/sp_MSforeachdb
- sp_MSforeach_Worker 批量清除数据库中被植入的js
- mssql里sp_MSforeachtable和sp_MSforeachdb的用法
- sp_MSforeachtable使用方法 查看库中所有表的空间大小
- sp_MSforeachtable 与 sp_MSforeachdb
- mssql里sp_MSforeachtable和sp_MSforeachdb的用法
- 详解SQL Server的两个存储过程:sp_MSforeachtable/sp_MSforeachdb
- sp_MSforeachtable使用方法
- sp_Msforeachtable与sp_Msforeachdb详解
- sp_MSforeachtable使用方法
- SQL Server 系统存储过程sp_MSforeachtable
- sp_MSforeachtable使用方法
- sp_MSforeachdb用法 (遍历数据库)