SQLServer2000數(shù)據(jù)庫(kù)系統(tǒng)表的應(yīng)用

字號(hào):

1:獲取當(dāng)前數(shù)據(jù)庫(kù)中的所有用戶(hù)表
    select Name from sysobjects where xtype='u' and status>=0
    2:獲取某一個(gè)表的所有字段
    select name from syscolumns where id=object_id('表名')
    3:查看與某一個(gè)表相關(guān)的視圖、存儲(chǔ)過(guò)程、函數(shù)
    select a.* from sysobjects a, syscomments b where a.id = b.id and b.text like '%表名%'
    4:查看當(dāng)前數(shù)據(jù)庫(kù)中所有存儲(chǔ)過(guò)程
    select name as 存儲(chǔ)過(guò)程名稱(chēng) from sysobjects where xtype='P'
    5:查詢(xún)用戶(hù)創(chuàng)建的所有數(shù)據(jù)庫(kù)
    select * from master..sysdatabases D where sid not in(select sid from master..syslogins where name='sa')
    或者
    select dbid, name AS DB_NAME from master..sysdatabases where sid <> 0x01
    6:查詢(xún)某一個(gè)表的字段和數(shù)據(jù)類(lèi)型
    select column_name,data_type from information_schema.columns
    where table_name = '表名'