MySql 查詢資料庫中所有表及列的資訊

2021-08-13 18:49:42 字數 711 閱讀 5120

mysql獲取某個資料庫的所有表名

select table_name from information_schema.tables where table_schema="your database name"

mysql獲取某個表的所有欄位名  

select column_name from information_schema.columns where table_name = 'your_table_name';

上述的做法有一點問題,如果多個資料庫中存在你想要查詢的表名,那麼查詢的結果會包括全部的字段資訊。通過desc information_schema.columns可以看到該表中列名為table_schema是記錄資料庫名,因此下面的寫法更為嚴格

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

mysql查詢資料庫中所有表及列的資訊

select

table_name,

column_name,

data_type,

column_comment

from

information_schema. columns

where

table_schema = '資料庫名'

查詢資料庫中所有的表

select from sysobjects where xtype u 查詢當前資料庫下所有使用者建立的表 xtype char 2 物件型別。可以是下列物件型別中的一種 c check 約束 d 預設值或 default 約束 f foreign key 約束 l 日誌 fn 標量函式 if 內...

查詢資料庫中所有表名,查詢表中所有欄位名

mysql 1.查詢資料庫中所有表名稱 select table name from information schema.tables where table schema 資料庫名稱 包含檢視 select table name from information schema.tables wh...

查詢資料庫中所有列名

如何從整個資料庫所有表中查詢出乙個列名?比如想要查詢乙個名為 name 的列名,但是忘記了這一列是在那乙個表中,需要從整個資料庫的所有表中進行查詢。oracle 資料庫 select from user col comments s where s.column name like name mys...