1. 程式人生 > >MySQL、SQL server 、Oracle資料庫中查詢所有的資料庫,查詢指定資料庫所有表名,查詢所有的欄位的名字

MySQL、SQL server 、Oracle資料庫中查詢所有的資料庫,查詢指定資料庫所有表名,查詢所有的欄位的名字

MySQL中查詢所有資料庫名和表名

1.查詢所有資料庫
show databases;

2.查詢指定資料庫中所有表名
select table_name from information_schema.tables where table_schema='database_name' and table_type='base table';

3.查詢指定表中的所有欄位名
select column_name from information_schema.columns where table_schema='database_name' and table_name='table_name';

4.查詢指定表中的所有欄位名和欄位型別
select column_name,data_type from information_schema.columns where table_schema='database_name' and table_name='table_name';

SQLServer中查詢所有資料庫名和表名

1、查詢資料庫中的所有資料庫名:
 SELECT * FROM Master..SysDatabases ORDER BY Name;

2、查詢當前資料庫所有表名:
SELECT * FROM SysObjects Where XType='U'   ORDER BY Name;
  --XType='U':表示所有使用者表; 
  --XType='S':表示所有系統表;

3.查詢某個表的所有欄位名: 
SELECT * FROM SysColumns WHERE id=Object_Id('TableName');

4.查詢指定表中的所有欄位名和欄位型別
select sc.name,st.name from syscolumns sc,systypes st where sc.xtype=st.xtype and sc.id in(select id from sysobjects where xtype='U' and name='table_name');

sqlserver中各個系統表的作用
sysaltfiles 主資料庫 儲存資料庫的檔案
syscharsets 主資料庫 字符集與排序順序
sysconfigures 主資料庫 配置選項
syscurconfigs 主資料庫 當前配置選項
sysdatabases 主資料庫 伺服器中的資料庫
syslanguages 主資料庫 語言
syslogins 主資料庫 登陸帳號資訊
sysoledbusers 主資料庫 連結伺服器登陸資訊
sysprocesses 主資料庫 程序
sysremotelogins主資料庫 遠端登入帳號
syscolumns 每個資料庫 列
sysconstrains 每個資料庫 限制
sysfilegroups 每個資料庫 檔案組
sysfiles 每個資料庫 檔案
sysforeignkeys 每個資料庫 外部關鍵字
sysindexs 每個資料庫 索引
sysmenbers 每個資料庫 角色成員
sysobjects 每個資料庫 所有資料庫物件
syspermissions 每個資料庫 許可權
systypes 每個資料庫 使用者定義資料型別
 

Oracle中查詢所有資料庫名和表名

1.查詢所有資料庫
由於Oralce沒有庫名,只有表空間,所以Oracle沒有提供資料庫名稱查詢支援,只提供了表空間名稱查詢。
select * from v$tablespace;--查詢表空間(需要一定許可權)

2.查詢當前資料庫中所有表名
select * from user_tables;

3.查詢指定表中的所有欄位名
select column_name from user_tab_columns where table_name = 'table_name';--表名要全大寫

4.查詢指定表中的所有欄位名和欄位型別
select column_name, data_type from user_tab_columns where table_name = 'table_name';--表名要全大寫