使用SQL語句查詢MySQL,SQLServer,Oracle所有資料庫名和表名,欄位名,mysqlsqlserver

來源:互聯網
上載者:User

使用SQL語句查詢MySQL,SQLServer,Oracle所有資料庫名和表名,欄位名,mysqlsqlserver

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

查詢所有資料庫

show databases;


查詢指定資料庫中所有表名

select table_name from information_schema.tables where table_schema='database_name' and table_type='base table';

查詢指定表中的所有欄位名

select column_name from information_schema.columns where table_schema='database_name' and table_name='table_name';

查詢指定表中的所有欄位名和欄位類型

select column_name,data_type from information_schema.columns where table_schema='database_name' and table_name='table_name';

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

查詢所有資料庫

select * from sysdatabases;

查詢當前資料庫中所有表名

select * from sysobjects where xtype='U';xtype='U':表示所有使用者表,xtype='S':表示所有系統資料表。

查詢指定表中的所有欄位名

select name from syscolumns where id=Object_Id('table_name');

查詢指定表中的所有欄位名和欄位類型

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');

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

查詢所有資料庫

由於Oralce沒有庫名,只有資料表空間,所以Oracle沒有提供資料庫名稱查詢支援,只提供了資料表空間名稱查詢。

select * from v$tablespace;--查詢資料表空間(需要一定許可權)

查詢當前資料庫中所有表名

select * from user_tables;

查詢指定表中的所有欄位名

select column_name from user_tab_columns where table_name = 'table_name';--表名要全大寫

查詢指定表中的所有欄位名和欄位類型

select column_name, data_type from user_tab_columns where table_name = 'table_name';-

使用SQL語句查詢MySQL,SQLServer,Oracle所有資料庫名和表名,欄位名的SQL語句,簡單明了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.