自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

MySQL默認(rèn)值和約束的查詢(xún)方法

數(shù)據(jù)庫(kù) MySQL
本文主要介紹關(guān)于MySQL默認(rèn)值和約束的查詢(xún)方法,下面,我們一起來(lái)看。

一、MySQL默認(rèn)值相關(guān)查詢(xún)

1. 列出 MySQL 數(shù)據(jù)庫(kù)中的表默認(rèn)值

select table_schema as database_name,
table_name,
column_name,
column_default
from information_schema.columns
where column_default is not null
and table_schema not in ('information_schema', 'sys',
'performance_schema','mysql')
-- and table_schema = 'your database name'
order by table_schema,
table_name,
ordinal_position;

說(shuō)明:

  • database_name - 數(shù)據(jù)庫(kù)的名稱(chēng)(模式)
  • table_name - 表的名稱(chēng)
  • column_name - 列的名稱(chēng)
  • column_default - 定義此列默認(rèn)值的 SQL 表達(dá)式

DBA技術(shù)分享(五)-mysql默認(rèn)值和約束的查詢(xún)方法

2. MySQL數(shù)據(jù)庫(kù)默認(rèn)值匯總

select column_default,
count(distinct concat(col.table_schema, '.', col.table_name)) as tables,
count(column_name) as columns
from information_schema.columns col
join information_schema.tables tab on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
where col.table_schema not in ('sys', 'information_schema',
'mysql', 'performance_schema')
and tab.table_type = 'BASE TABLE'
group by column_default
order by tables desc,
columns desc;

說(shuō)明:

  • column_default -為沒(méi)有默認(rèn)值的列定義默認(rèn)約束(公式)和NULL
  • tables- 具有此約束的表數(shù)(或具有對(duì)NULL行沒(méi)有約束的列的表數(shù))
  • columns - 具有此特定約束的列數(shù)(或NULL行沒(méi)有約束)

DBA技術(shù)分享(五)-mysql默認(rèn)值和約束的查詢(xún)方法

二、約束

1. 列出了數(shù)據(jù)庫(kù)(模式)中的所有不可為空的列

select tab.table_schema as database_name,
tab.table_name,
col.ordinal_position as column_id,
col.column_name,
col.data_type,
case when col.numeric_precision is not null
then col.numeric_precision
else col.character_maximum_length end as max_length,
case when col.datetime_precision is not null
then col.datetime_precision
when col.numeric_scale is not null
then col.numeric_scale
else 0 end as 'precision'
from information_schema.tables as tab
join information_schema.columns as col
on col.table_schema = tab.table_schema
and col.table_name = tab.table_name
and col.is_nullable = 'no'
where tab.table_schema not in ('information_schema', 'sys',
'mysql','performance_schema')
and tab.table_type = 'BASE TABLE'
-- and tab.table_schema = 'database name'
order by tab.table_schema,
tab.table_name,
col.ordinal_position;

注意:如果您需要特定數(shù)據(jù)庫(kù)(模式)的信息,請(qǐng)取消注釋 where 子句中的條件并提供您的數(shù)據(jù)庫(kù)名稱(chēng)。

說(shuō)明:

  • database_name - 數(shù)據(jù)庫(kù)的名稱(chēng)(模式)
  • table_name - 表的名稱(chēng)
  • column_id - 列在表中的位置
  • column_name - 列的名稱(chēng)
  • data_type - 列數(shù)據(jù)類(lèi)型
  • max_length - 數(shù)據(jù)類(lèi)型的最大長(zhǎng)度
  • precision- 數(shù)據(jù)類(lèi)型的精度

DBA技術(shù)分享(五)-mysql默認(rèn)值和約束的查詢(xún)方法

2. 檢查 MySQL 數(shù)據(jù)庫(kù)中的列是否可為空

select c.table_schema as database_name,
c.table_name,
c.column_name,
case c.is_nullable
when 'NO' then 'not nullable'
when 'YES' then 'is nullable'
end as nullable
from information_schema.columns c
join information_schema.tables t
on c.table_schema = t.table_schema
and c.table_name = t.table_name
where c.table_schema not in ('mysql', 'sys', 'information_schema',
'performance_schema')
and t.table_type = 'BASE TABLE'
-- and t.table_schema = 'database_name' -- put your database name here
order by t.table_schema,
t.table_name,
c.column_name;

說(shuō)明:

  • database_name - 數(shù)據(jù)庫(kù)名稱(chēng)(模式)
  • table_name - 表名
  • column_name - 列名
  • nullable- 列的可空性屬性:is nullable- 可以為空,not nullable- 不可為空

DBA技術(shù)分享(五)-mysql默認(rèn)值和約束的查詢(xún)方法

責(zé)任編輯:趙寧寧 來(lái)源: 今日頭條
相關(guān)推薦

2010-11-23 16:49:42

MySQL設(shè)置當(dāng)前時(shí)間

2011-05-20 11:33:06

ORACLE索引約束

2010-06-10 17:59:05

2019-11-15 10:01:07

MySQL數(shù)據(jù)庫(kù)數(shù)據(jù)

2021-02-25 13:40:17

MySQL數(shù)據(jù)庫(kù)默認(rèn)值

2010-11-25 16:40:11

MySQL大表重復(fù)字段

2009-08-19 15:08:30

C#泛型

2010-10-22 16:56:35

sql server刪

2009-06-08 10:20:01

Hibernate查詢(xún)

2009-06-17 15:52:23

Hibernate查詢(xún)

2010-11-15 16:26:46

Oracle系統(tǒng)時(shí)間

2010-10-29 11:22:23

Oracle用戶(hù)會(huì)話(huà)

2010-09-28 10:23:36

SQL修改字段

2012-08-01 09:50:11

交互設(shè)計(jì)UI設(shè)計(jì)

2009-05-21 09:24:42

表空間查詢(xún)Oracle

2009-06-29 09:03:31

Hibernate多條

2018-09-06 16:46:33

數(shù)據(jù)庫(kù)MySQL分頁(yè)查詢(xún)

2013-05-27 10:11:25

路由器查詢(xún)方式路由器遞歸查詢(xún)路由器撲朔圖

2012-07-30 09:50:28

MongoDB

2010-09-14 15:51:15

sql遍歷
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)