成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

MySQL默認值和約束的查詢方法

數據庫 MySQL
本文主要介紹關于MySQL默認值和約束的查詢方法,下面,我們一起來看。

一、MySQL默認值相關查詢

1. 列出 MySQL 數據庫中的表默認值

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;

說明:

  • database_name - 數據庫的名稱(模式)
  • table_name - 表的名稱
  • column_name - 列的名稱
  • column_default - 定義此列默認值的 SQL 表達式

DBA技術分享(五)-mysql默認值和約束的查詢方法

2. MySQL數據庫默認值匯總

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;

說明:

  • column_default -為沒有默認值的列定義默認約束(公式)和NULL
  • tables- 具有此約束的表數(或具有對NULL行沒有約束的列的表數)
  • columns - 具有此特定約束的列數(或NULL行沒有約束)

DBA技術分享(五)-mysql默認值和約束的查詢方法

二、約束

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

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;

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

說明:

  • database_name - 數據庫的名稱(模式)
  • table_name - 表的名稱
  • column_id - 列在表中的位置
  • column_name - 列的名稱
  • data_type - 列數據類型
  • max_length - 數據類型的最大長度
  • precision- 數據類型的精度

DBA技術分享(五)-mysql默認值和約束的查詢方法

2. 檢查 MySQL 數據庫中的列是否可為空

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;

說明:

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

DBA技術分享(五)-mysql默認值和約束的查詢方法

責任編輯:趙寧寧 來源: 今日頭條
相關推薦

2010-11-23 16:49:42

MySQL設置當前時間

2011-05-20 11:33:06

ORACLE索引約束

2010-06-10 17:59:05

2019-11-15 10:01:07

MySQL數據庫數據

2010-11-25 16:40:11

MySQL大表重復字段

2021-02-25 13:40:17

MySQL數據庫默認值

2009-08-19 15:08:30

C#泛型

2010-10-22 16:56:35

sql server刪

2009-06-08 10:20:01

Hibernate查詢

2009-06-17 15:52:23

Hibernate查詢

2010-11-15 16:26:46

Oracle系統時間

2010-10-29 11:22:23

Oracle用戶會話

2010-09-28 10:23:36

SQL修改字段

2009-05-21 09:24:42

表空間查詢Oracle

2009-06-29 09:03:31

Hibernate多條

2012-08-01 09:50:11

交互設計UI設計

2018-09-06 16:46:33

數據庫MySQL分頁查詢

2013-05-27 10:11:25

路由器查詢方式路由器遞歸查詢路由器撲朔圖

2012-07-30 09:50:28

MongoDB

2022-11-07 08:00:00

機器學習數字孿生數據科學
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 亚洲国产高清在线 | 天天搞天天操 | 免费黄色的网站 | 欧美一区二区三区在线看 | 男女羞羞免费网站 | 免费黄色成人 | 久久免费精品 | 久久国产成人 | 亚洲精品日韩一区二区电影 | 在线观看av网站永久 | 亚洲精品乱 | 在线a视频网站 | 亚洲交性| 日韩一区在线播放 | 欧美激情久久久 | 国产免费一区二区三区 | 久久久女女女女999久久 | 久久大| 成人免费激情视频 | 成人性视频在线播放 | 国产女人精品视频 | 亚洲一区二区三区免费视频 | 成人免费淫片aa视频免费 | 久久久久一区二区三区 | 日日射夜夜骑 | 看av片网站 | 狠狠av| 福利在线观看 | 日韩国产欧美视频 | h视频免费在线观看 | 久久久久久久综合色一本 | 成人在线播放网址 | 久久久久国产一区二区 | 国产欧美精品区一区二区三区 | 欧美成视频在线观看 | 成人一级黄色毛片 | 欧美精品在欧美一区二区少妇 | 在线免费观看黄a | www国产成人免费观看视频 | 日本精品免费 | 久久精彩视频 |