博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql server 约束 查找
阅读量:6656 次
发布时间:2019-06-25

本文共 1915 字,大约阅读时间需要 6 分钟。

主键约束SELECT  tab.name AS [表名],  idx.name AS [主键名称],  col.name AS [主键列名]FROM  sys.indexes idx    JOIN sys.index_columns idxCol       ON (idx.object_id = idxCol.object_id           AND idx.index_id = idxCol.index_id           AND idx.is_primary_key = 1)    JOIN sys.tables tab      ON (idx.object_id = tab.object_id)    JOIN sys.columns col      ON (idx.object_id = col.object_id          AND idxCol.column_id = col.column_id); 唯一约束SELECT  tab.name AS [表名],  idx.name AS [约束名称],  col.name AS [约束列名]FROM  sys.indexes idx    JOIN sys.index_columns idxCol       ON (idx.object_id = idxCol.object_id           AND idx.index_id = idxCol.index_id           AND idx.is_unique_constraint = 1)    JOIN sys.tables tab      ON (idx.object_id = tab.object_id)    JOIN sys.columns col      ON (idx.object_id = col.object_id          AND idxCol.column_id = col.column_id); 外键约束select  oSub.name  AS  [子表名称],  fk.name AS  [外键名称],  SubCol.name AS [子表列名],  oMain.name  AS  [主表名称],  MainCol.name AS [主表列名]from  sys.foreign_keys fk      JOIN sys.all_objects oSub          ON (fk.parent_object_id = oSub.object_id)    JOIN sys.all_objects oMain         ON (fk.referenced_object_id = oMain.object_id)    JOIN sys.foreign_key_columns fkCols         ON (fk.object_id = fkCols.constraint_object_id)    JOIN sys.columns SubCol         ON (oSub.object_id = SubCol.object_id              AND fkCols.parent_column_id = SubCol.column_id)    JOIN sys.columns MainCol         ON (oMain.object_id = MainCol.object_id              AND fkCols.referenced_column_id = MainCol.column_id) Check约束SELECT  tab.name AS [表名],  chk.name AS [Check约束名],  col.name AS [列名],  chk.definitionFROM  sys.check_constraints chk    JOIN sys.tables tab      ON (chk.parent_object_id = tab.object_id)    JOIN sys.columns col      ON (chk.parent_object_id = col.object_id          AND chk.parent_column_id = col.column_id)

转载于:https://www.cnblogs.com/fyq891014/p/5057973.html

你可能感兴趣的文章
Scenario 6 –HP C7000 Virtual Connect FlexFabric SUS with A/A Uplinks, 8
查看>>
Java 框架新贵入驻 TechEmpower Framework Benchmark
查看>>
CentOS6.3 64位安装wine出错,牛人帮帮忙
查看>>
国内的Maven服务器
查看>>
C# winform DataGridView 的18种常见属性
查看>>
MySQL存储过程
查看>>
ANTLR Reference书摘
查看>>
我的友情链接
查看>>
Ubuntu Mate:扩展存储到整张SD卡
查看>>
es学习5-slowlog
查看>>
nf_conntrack: table full, dropping packet
查看>>
Linux的五个查找命令:find,locate,whereis,which,type
查看>>
读写者锁与生产者/消费者模式
查看>>
关于python中的if __name__=='__main__'语句问题
查看>>
线程组
查看>>
涉密数据的处理
查看>>
python简介
查看>>
python字典开发三级菜单
查看>>
.net Framework下载地址
查看>>
深圳偶遇
查看>>