MySql查詢庫結構及表屬性SQL總結

2021-10-20 15:33:29 字數 2868 閱讀 2752

select

user

,host from mysql.

user

select schema_name dbname,default_character_set_name code from information_schema.schemata 

order

by schema_name

select table_name as tablename,table_schema owner,table_rows num_rows,check_time last_analyzed 

from information_schema.

tables

where table_schema =

'資料庫名'

and table_type=

'base table'

select table_schema,table_name,view_definition from  information_schema.views 

where table_schema=

'資料庫名'

select trigger_schema,trigger_name,action_timing,event_manipulation,

event_object_table,action_orientation,action_statement

from information_schema.triggers where trigger_schema=

'資料庫名'

select table_schema,table_name,column_name,data_type,is_nullable,column_type,column_key 

from information_schema.

columns

where table_schema =

'資料庫名'

and table_name=

'表名'

select a.column_name,a.constraint_name 

from information_schema.key_column_usage a,information_schema.table_constraints b

where a.table_schema=b.table_schema and a.table_name=b.table_name

and a.constraint_name=b.constraint_name and b.constraint_type =

'primary key'

and a.table_schema=

'資料庫名'

and a.table_name=

'表名'

select a.constraint_name,

a.table_schema,a.table_name,a.column_name,

a.referenced_table_schema,a.referenced_table_name,a.referenced_column_name

from information_schema.key_column_usage a,information_schema.table_constraints b

where a.table_schema=b.table_schema and a.table_name=b.table_name

and a.constraint_name=b.constraint_name and b.constraint_type =

'foreign key'

and a.table_schema=

'資料庫名'

and a.table_name=

'表名'

show

index

from

`資料庫名`

.`表名`

where key_name notin(

select a.constraint_name

from information_schema.key_column_usage a,information_schema.table_constraints b

where a.table_schema=b.table_schema and a.table_name=b.table_name

and a.constraint_name=b.constraint_name

and a.table_schema=

'資料庫名'

and a.table_name=

'表名'

)

select a.constraint_name,a.column_name 

from information_schema.key_column_usage a,information_schema.table_constraints b

where a.table_schema=b.table_schema and a.table_name=b.table_name

and a.constraint_name=b.constraint_name and b.constraint_type =

'unique'

and a.table_schema=

'資料庫名'

and a.table_name=

'表名'

【注意】本文的sql均自測於mysql5.7版本

查詢mysql表結構的語句 查詢表結構的slq語句

1.mysql 和 sqlserver 資料庫 檢視表結構 select from information schema.columns where table name 表名 修改字段長度 alter table 表名 alter column 欄位名 字段型別 字段長度 oracle 資料庫 檢...

mysql 查詢表結構

檢視表中字段的結構資訊 可以用來檢視表中字段的注釋等,比如 select table name,column name,column comment from information schema.columns where table schema 表所在的庫 and table name 要檢視...

oracle資料庫入門 查詢表及表結構

獲取表 select table name from user tables 當前使用者的表 select table name from all tables 所有使用者的表 select table name from dba tables 包括系統表 select table name fro...