删除所有表中的数据 :
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'