sys.tables

是sqlserver2005版本中新增一個目錄視圖,它存儲了當前資料庫中的所有表信息,在功能上大致和sqlserver2005之前版本的select * from sysobjects where xtype="u"的功能一樣。

介紹

sys.tables是sqlserver2005版本中新增一個目錄視圖,它存儲了當前資料庫中的所有表信息,在功能上大致和sqlserver2005之前版本的select * from sysobjects where xtype="u"的功能一樣。

列說明

列名數據類型說明
lob_data_space_id int
filestream_data_space_id int 僅限內部系統使用。
max_column_id_used int 此表曾使用的最大列 ID。
lock_on_bulk_load bit 鎖被鎖定於大容量裝載。有關詳細信息,請參閱 sp_tableoption (Transact-SQL)。
uses_ansi_nulls bit 創建表時,SET ANSI_NULLS 資料庫選項設定為 ON。
is_replicated bit 1 = 使用快照複製或事務複製發布表。
has_replication_filter bit 1 = 表具有複製篩選器。
is_merge_published bit 1 = 使用合併複製發布表。
is_sync_tran_subscribed bit 1 = 使用立即更新訂閱來訂閱表。
has_unchecked_assembly_data bit 1 = 表包含的持久化數據依賴於上次 ALTER ASSEMBLY 期間其定義發生更改的程式集。在下一次成功執行 DBCC CHECKDB 或 DBCC CHECKTABLE 後將重置為 0。
text_in_row_limit int Text in row 的最大允許位元組數。 0 = 未設定 Text in row 選項。有關詳細信息,請參閱 sp_tableoption (Transact-SQL)。
large_value_types_out_of_row bit 1 = 超行存儲大值類型。有關詳細信息,請參閱 sp_tableoption (Transact-SQL)。

套用示例

1,查看當前資料庫的所有表

select * from sys.tables

2,查詢資料庫中所有表的數據行數

declare @TableName varchar(128)

declare @T_TableRows Table

(

TableName varchar(128) not null,

RowsCount int not null default(0)

)

declare cur_table cursor local for

select name from sys.tables order by name

open cur_table

fetch cur_table into @TableName

while @@fetch_status = 0

begin

insert into @T_TableRows(TableName,RowsCount)

exec('select ''' + @TableName + ''',count(*) from ' + @TableName)

fetch cur_table into @TableName

end

close cur_table

deallocate cur_table

3,刪除資料庫中所有表中的數據

declare @TableName varchar(128)

declare cur_table cursor local for

select name from sys.tables order by name

open cur_table

fetch cur_table into @TableName

while @@fetch_status = 0

begin

exec('delete from ' + @TableName + ')

fetch cur_table into @TableName

end

close cur_table

deallocate cur_table

相關詞條

熱門詞條

聯絡我們