1.查看數據庫中所有表名稱:
select Name from sysobjects where xtype='U' order by name asc;
sysobjects是系統表,關於SQL Server數據庫的一切信息都保存在系統表中
2.刪除整個數據庫表數據:
declare c cursor for --定義游標
select NAME from sysobjects where xtype='U'
declare @t varchar(20)
open c
fetch next from c into @t
while @@FETCH_STATUS=0
begin
print @t
exec('truncate table '+@t)
--exec('delete from '+@t)
fetch next from c into @t
end
close c
xtype | char(2) | 對象類型。常用列。xtype可以是下列對象類型中的一種: C = CHECK 約束 D = 默認值或 DEFAULT 約束 F = FOREIGN KEY 約束 L = 日志 FN = 標量函數 IF = 內嵌表函數 P = 存儲過程 PK = PRIMARY KEY 約束(類型是 K) RF = 復制篩選存儲過程 S = 系統表 TF = 表函數 TR = 觸發器 U = 用戶表 UQ = UNIQUE 約束(類型是 K) V = 視圖 X = 擴展存儲過程 |