日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
MySQL默認(rèn)值和約束的查詢(xún)方法

一、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ō)明:

創(chuàng)新互聯(lián)公司專(zhuān)注為客戶(hù)提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、成都網(wǎng)站制作、梁園網(wǎng)絡(luò)推廣、成都小程序開(kāi)發(fā)、梁園網(wǎng)絡(luò)營(yíng)銷(xiāo)、梁園企業(yè)策劃、梁園品牌公關(guān)、搜索引擎seo、人物專(zhuān)訪(fǎng)、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供梁園建站搭建服務(wù),24小時(shí)服務(wù)熱線(xiàn):028-86922220,官方網(wǎng)址:www.cdcxhl.com

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

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)有約束)

二、約束

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)型的精度

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- 不可為空

文章名稱(chēng):MySQL默認(rèn)值和約束的查詢(xún)方法
文章位置:http://www.dlmjj.cn/article/cogghee.html