日期:2011-01-25 23:11:00 来源:本站整理
两种数据库中查询表主键外键信息的SQL语句[MSSQL防范]
本文“两种数据库中查询表主键外键信息的SQL语句[MSSQL防范]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
下文为您介绍Oracle及SQL Server两种数据库中查询表主键外键信息的SQL语句写法,供您参考,但愿对您学习SQL语句的利用有所启迪.
Oracle:
- select o.obj# as objectId, o.name AS tableName, oc.name AS constraintName,
- decode(c.type#, 1, 'C', 2, 'P', 3, 'U',
- 4, 'R', 5, 'V', 6, 'O', 7,'C', '?') as constraintType,
- col.name AS columnName
- from sys.con$ oc, sys.con$ rc,
- sys.obj$ ro,sys.obj$ o, sys.obj$ oi,
- sys.cdef$ c,
- sys.col$ col, sys.ccol$ cc, sys.attrcol$ ac
- where oc.con# = c.con#
- and c.obj# = o.obj#
- and c.rcon# = rc.con#(+)
- and c.enabled = oi.obj#(+)
- and c.robj# = ro.obj#(+)
- and c.type# != 8
- and c.type# != 12 /* don't include log groups */
- 字串9
- and c.con# = cc.con#
- and cc.obj# = col.obj#
- and cc.intcol# = col.intcol#
- and cc.obj# = o.obj#
- and col.obj# = ac.obj#(+)
- and col.intcol# = ac.intcol#(+)
- and o.name = 'your table'
SQL Server:
<
- SELECT sysobjects.id objectId,
- OBJECT_NAME(sysobjects.parent_obj) tableName,
- sysobjects.name constraintName,
- sysobjects.xtype AS constraintType,
- syscolumns.name AS columnName
- FROM sysobjects INNER JOIN sysconstraints
- ON sysobjects.xtype in('C', 'F', 'PK', 'UQ', 'D')
- AND sysobjects.id = sysconstraints.constid
- LEFT OUTER JOIN syscolumns ON sysconstraints.id = syscolumns.id
- WHERE OBJECT_NAME(sysobjects.parent_obj)='your table'
以上是“两种数据库中查询表主键外键信息的SQL语句[MSSQL防范]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论