数据库元数据数据字典查询_8_列出给定表的默认约束
生活随笔
收集整理的這篇文章主要介紹了
数据库元数据数据字典查询_8_列出给定表的默认约束
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ?列出給定表的默認約束
需求描述
需求:查詢出給定的表emp的默認約束(default)信息。
解決方法:通過各個數據庫里提供的與默認約束(default)相關的數據字典進行查詢。
注: 數據庫數據集SQL腳本詳見如下鏈接地址
員工表結構和數據初始化SQL腳本
SQL代碼
-- Sql Server:-- 新增default約束以設置emp表的comm默認值是0 alter table EMP drop constraint DF_EMP_Comm alter table EMP add constraint DF_EMP_Comm DEFAULT ((0)) for comm alter table EMP with check add constraint DF_EMP_Comm DEFAULT ((0)) for comm alter table EMP with nocheck add constraint DF_EMP_Comm DEFAULT ((0)) for commSELECT A.name AS DFConstraint_Name,B.name AS Table_Name,C.name AS DFConstraint_ColumnName,A.definition AS DF_Def,A.create_date AS Create_time,A.modify_date AS Modify_time FROM sys.default_constraints A JOIN sys.tables BON A.parent_object_id = B.object_id JOIN sys.columns CON B.object_id = C.object_id AND A.parent_column_id = C.column_id執行結果
-- Mysql: SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT FROM information_schema.columns WHERE TABLE_NAME = 'EMP' AND column_default IS NOT NULL-- Oracle: alter table EMP modify comm default 0;SELECT t.COLUMN_NAME,t.nullable, t.data_default FROM USER_TAB_COLS t WHERE TABLE_NAME ='EMP'AND data_default IS NOT NULL?
總結
以上是生活随笔為你收集整理的数据库元数据数据字典查询_8_列出给定表的默认约束的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 联想公司回科创板上市 消息称将募资超百亿
- 下一篇: 万达普惠有额度不能用怎么回事