查询表主键外键信息的SQL
2007-11-11 13:03:43 来源:WEB开发网我的BSOOC里需要一个查询表主键外键信息的SQL,昨晚研究到凌晨1点,终于能实现这个目标:
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(WINDOWS平台上强大的数据库平台):
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 Server 2008 R2 下如何清理数据库日志文件
- ››sqlite 存取中文的解决方法
- ››SQL2005、2008、2000 清空删除日志
- ››SQL Server 2005和SQL Server 2000数据的相互导入...
- ››sql server 2008 在安装了活动目录以后无法启动服...
- ››sqlserver 每30分自动生成一次
- ››sqlite 数据库 对 BOOL型 数据的插入处理正确用法...
- ››sql server自动生成批量执行SQL脚本的批处理
- ››sql server 2008亿万数据性能优化
- ››SQL Server 2008清空数据库日志方法
- ››sqlserver安装和简单的使用
- ››SQL Sever 2008 R2 数据库管理
赞助商链接