成人免费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設置當前時間

2010-06-10 17:59:05

2011-05-20 11:33:06

ORACLE索引約束

2019-11-15 10:01:07

MySQL數據庫數據

2010-11-25 16:40:11

MySQL大表重復字段

2009-08-19 15:08:30

C#泛型

2021-02-25 13:40:17

MySQL數據庫默認值

2010-10-22 16:56:35

sql server刪

2009-06-08 10:20:01

Hibernate查詢

2010-10-29 11:22:23

Oracle用戶會話

2010-11-15 16:26:46

Oracle系統時間

2009-06-17 15:52:23

Hibernate查詢

2010-09-28 10:23:36

SQL修改字段

2009-06-29 09:03:31

Hibernate多條

2018-09-06 16:46:33

數據庫MySQL分頁查詢

2009-05-21 09:24:42

表空間查詢Oracle

2012-08-01 09:50:11

交互設計UI設計

2022-11-07 08:00:00

機器學習數字孿生數據科學

2010-09-14 15:51:15

sql遍歷

2013-05-27 10:11:25

路由器查詢方式路由器遞歸查詢路由器撲朔圖
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 免费国产精品久久久久久 | 国产精品免费高清 | 国产成人精品一区二 | 精彩视频一区二区三区 | 精品视频免费 | 亚洲首页 | 天堂一区在线观看 | 91精品国产美女在线观看 | 日日操av | 精品久久久久久亚洲综合网 | 精品九九 | 国产日韩欧美二区 | 国产伦精品一区二区三区照片91 | 好好的日在线视频 | 偷拍自拍网址 | www.精品一区 | 国产视频在线一区二区 | 国产不卡一区 | 毛片国产 | 精品一级毛片 | 日韩欧美精品一区 | 欧美a级成人淫片免费看 | 中文字幕视频在线看5 | 国产成人综合av | 欧美日韩中文字幕在线 | 爱综合 | 精品免费国产一区二区三区 | 国产综合精品 | 欧美在线视频网 | 成人久久久久久久久 | 日韩国产三区 | 精品国产欧美一区二区三区成人 | 91免费版在线 | 日韩欧美国产精品一区二区 | 日韩久久久久久 | 日韩av中文| 国产午夜精品一区二区三区在线观看 | 狠狠操电影 | 国产精品成人一区二区三区 | 久久久av| 欧美一区二区三区的 |