自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

兩種數(shù)據(jù)庫中查詢表主鍵外鍵信息的SQL語句

數(shù)據(jù)庫 SQL Server
有時(shí)我們需要一個(gè)查詢表主鍵外鍵信息的SQL語句,下面就將為您介紹該語句的寫法,如果您對此有興趣的話,不妨一看。

下文為您介紹Oracle及SQL Server兩種數(shù)據(jù)庫中查詢表主鍵外鍵信息的SQL語句寫法,供您參考,希望對您學(xué)習(xí)SQL語句的使用有所啟迪。

Oracle:

  1. select o.obj# as objectId, o.name AS tableName, oc.name AS constraintName,  
  2.        decode(c.type#, 1, 'C', 2, 'P', 3, 'U',  
  3.               4, 'R', 5, 'V', 6, 'O', 7,'C', '?') as constraintType,   
  4.        col.name AS columnName  
  5.         
  6. from sys.con$ oc, sys.con$ rc,   
  7.      sys.obj$ ro,sys.obj$ o, sys.obj$ oi,  
  8.      sys.cdef$ c,  
  9.      sys.col$ col, sys.ccol$ cc, sys.attrcol$ ac  
  10. where oc.con# = c.con#  
  11.   and c.obj# = o.obj#  
  12.   and c.rcon# = rc.con#(+)  
  13.   and c.enabled = oi.obj#(+)  
  14.   and c.robj# = ro.obj#(+)  
  15.   and c.type# != 8  
  16.   and c.type# != 12       /* don't include log groups */   
  17.  
  18. 字串9  
  19.  
  20.   and c.con# = cc.con#  
  21.   and cc.obj# = col.obj#  
  22.   and cc.intcol# = col.intcol#  
  23.   and cc.obj# = o.obj#  
  24.   and col.obj# = ac.obj#(+)  
  25.   and col.intcol# = ac.intcol#(+)  
  26.   and o.name = 'your table' 

SQL Server:
 

  1. SELECT sysobjects.id objectId,  
  2. OBJECT_NAME(sysobjects.parent_obj) tableName,  
  3. sysobjects.name constraintName,   
  4. sysobjects.xtype AS constraintType,  
  5. syscolumns.name AS columnName  
  6. FROM sysobjects INNER JOIN sysconstraints  
  7. ON sysobjects.xtype in('C', 'F', 'PK', 'UQ', 'D')   
  8.  AND sysobjects.id = sysconstraints.constid  
  9. LEFT OUTER JOIN syscolumns ON sysconstraints.id = syscolumns.id  
  10. WHERE OBJECT_NAME(sysobjects.parent_obj)='your table'  

 

 

【編輯推薦】

修改SQL主鍵約束的SQL語句寫法

對存儲(chǔ)過程代替SQL語句的討論

試SQL語句執(zhí)行時(shí)間的方法

SQL語句中的SELECT DISTINCT

如何使用SQL語句修改字段默認(rèn)值

責(zé)任編輯:段燃 來源: 互聯(lián)網(wǎng)
相關(guān)推薦

2011-05-07 15:38:30

MySQL數(shù)據(jù)引擎

2010-09-25 15:37:38

SQL語句

2011-08-03 10:04:57

SQL Server數(shù)沒有主鍵的表

2010-10-09 10:29:29

MySQL外鍵

2010-01-05 09:24:42

MySQL外鍵約束

2010-09-26 16:31:13

隨機(jī)查詢語句

2010-09-02 10:02:06

SQL刪除

2019-11-05 08:20:13

MySQL數(shù)據(jù)庫外鍵

2011-04-06 11:05:21

SQL Server數(shù)交換數(shù)據(jù)

2010-09-02 10:36:51

SQL刪除

2011-05-13 13:38:49

數(shù)據(jù)庫對象

2017-11-02 14:12:07

2010-05-17 16:10:39

MySQL數(shù)據(jù)庫

2023-09-08 08:44:09

Oracle數(shù)據(jù)庫

2010-11-10 11:37:29

SQL Server刪

2011-07-25 18:11:47

SQL Server數(shù)復(fù)合主鍵

2019-10-21 08:08:34

MySQL數(shù)據(jù)庫主鍵

2022-06-26 06:32:28

MySQL數(shù)據(jù)庫維護(hù)

2011-08-30 17:48:48

Oracle數(shù)據(jù)庫日期to_char方式to_date方式

2010-09-08 16:03:57

SQL臨時(shí)表數(shù)據(jù)庫
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)