sql server 查詢資料庫所有的表名 字段

2021-08-10 11:26:59 字數 2251 閱讀 4347

執行一條sql語句:

select * from information_schema.columns where table_name='subject'(表名)

1.利用

sysobjects

系統表 在這個表中,在資料庫中建立的每個物件(例如約束、預設值、日誌、規則以及儲存過程)都有對應一行,我們在該表中篩選出xtype等於u的所有記錄,就為資料庫中的表了。 示例語句如下:

select * from sysobjects where xtype='u'

注意:在sql server2005中,出現了sys.objects目錄檢視來代替sysobjects系統表,我們在sql server2005及以後的版本中,可以使用sysobjects系統表與sys.objects目錄檢視的任意物件來查詢所有表。

2,利用

sys.tables

目錄檢視 sys.tables目錄檢視,為每個表物件返回一行. 示例語句如下:

select * from sys.tables

注意:sys.tables目錄檢視也只有在sql server2005及以上的版本中才能使用。

3,利用

儲存過程sp_tables sp_tables

儲存過程,可返回可在當前環境中查詢的物件列表。這代表可在from子句中出現的任何物件。 我們可以執行如下語句:

exec sp_tables

在結果集中篩選出所有table_type等於table的記錄就是表資訊了。

--讀取庫中的所有表名

select name from sysobjects where xtype='u'

--讀取指定表的所有列名

select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='表名')

獲取資料庫表名和字段

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'要查的表名')

另支援:

查詢資料庫裡所有表名和欄位名的語句

sql 查詢所有表名:

select name from sysobjects where type='u'

select * from information_schema.tables

查詢表的所有欄位名:

select name from syscolumns where id=object_id(' 表名' )

select * from information_schema.tables

select * from information_schema.views

select * from information_schema.columns

oracle 檢視所有表名:

select table_name from user_tables

access 檢視所有表名:

select name from msysobjects where type=1 and flags=0

msysobjects 是系統物件,預設情況是隱藏的。通過工具、選項、檢視、顯示、系統物件可以使之顯示出來。

SQL Server資料庫查詢

開啟我們的sql server資料庫,找到要查詢的資料庫表,右鍵單擊然後選擇新建查詢,select 選擇我們要查詢的表sys academe學院表 聯合 sys class.classname班級表的班級名稱和sys grade.gradename年級表的年級編號來查詢出資料。下面是查詢的 sele...

SQL Server 跨資料庫查詢

語句 select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field dbo 可以省略 如 select from 資料庫a.表a a,資料庫b.表b b where a.field b.field sqlserver資料庫 這句是對映乙個...

查詢SQL SERVER 資料庫版本

select substring cast serverproperty productversion as nvarchar 128 1,charindex cast serverproperty productversion as nvarchar 128 1 1 8 對應 sql server...