刪除所有表中的數據 :
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'