国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

查詢表主鍵外鍵信息的SQL

2024-07-21 02:10:35
字體:
供稿:網(wǎng)友

我的bsooc里需要一個查詢表主鍵外鍵信息的sql,昨晚研究到凌晨1點,終于能實現(xiàn)這個目標(biāo):
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 */
  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'
 
其它數(shù)據(jù)庫還沒時間去實現(xiàn).

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 满洲里市| 普兰县| 土默特右旗| 砀山县| 焉耆| 鹿邑县| 阳朔县| 清镇市| 柳州市| 楚雄市| 夏河县| 杭锦后旗| 德江县| 神木县| 望谟县| 南乐县| 高邮市| 公主岭市| 绥德县| 洱源县| 饶阳县| 黄大仙区| 平顶山市| 莲花县| 资源县| 祁门县| 临朐县| 武山县| 崇明县| 东山县| 闽清县| 扬中市| 东宁县| 上虞市| 新郑市| 铜川市| 庆阳市| 且末县| 永安市| 松潘县| 房山区|