1. 程式人生 > >SQL如何查詢一個數據庫中的所有表?

SQL如何查詢一個數據庫中的所有表?

1.讀取庫中的所有表名
select name from sysobjects where xtype='u'
2.讀取指定表的所有列名
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='表名')
3.獲取資料庫表名和欄位
sqlserver中各個系統表的作用
sysaltfiles 主資料庫 儲存資料庫的檔案
syscharsets 主資料庫 字符集與排序順序
sysconfigures 主資料庫 配置選項
syscurconfigs 主資料庫 當前配置選項
sysdatabases 主資料庫 伺服器中的資料庫
syslanguages 主資料庫 語言
syslogins 主資料庫 登陸帳號資訊
sysoledbusers 主資料庫 連結伺服器登陸資訊
sysprocesses 主資料庫 程序
sysremotelogins主資料庫 
遠端登入
帳號 syscolumns 每個資料庫 列 sysconstrains 每個資料庫 限制 sysfilegroups 每個資料庫 檔案組 sysfiles 每個資料庫 檔案 sysforeignkeys 每個資料庫 外部關鍵字 sysindexs 每個資料庫 索引 sysmenbers 每個資料庫 角色成員 sysobjects 每個資料庫 所有資料庫物件 syspermissions 每個資料庫 許可權 systypes 每個資料庫 使用者定義資料型別 select 列名=name from syscolumns where id=object_id(N'要查的表名')