IT貓撲網(wǎng):您身邊最放心的安全下載站! 最新更新|軟件分類|軟件專題|手機(jī)版|論壇轉(zhuǎn)貼|軟件發(fā)布

您當(dāng)前所在位置: 首頁(yè)數(shù)據(jù)庫(kù)Oracle → Oracle與SqlServer中獲取所有字段、主鍵、外鍵的sql語(yǔ)句

Oracle與SqlServer中獲取所有字段、主鍵、外鍵的sql語(yǔ)句

時(shí)間:2015-06-28 00:00:00 來(lái)源:IT貓撲網(wǎng) 作者:網(wǎng)管聯(lián)盟 我要評(píng)論(0)

  Oracle:

  查詢某個(gè)表中的字段名稱、類型、精度、長(zhǎng)度、是否為空

  select COLUMN_NAME,DATA_TYPE,DATA_PRECISION,DATA_SCALE,NULLABLE

  from user_tab_columns

  where table_name ='YourTableName'

  查詢某個(gè)表中的主鍵字段名

  select col.column_name

  from user_constraints con,? user_cons_columns col

  where con.constraint_name = col.constraint_name

  and con.constraint_type='P'

  and col.table_name = 'YourTableName'

  查詢某個(gè)表中的外鍵字段名稱、所引用表名、所應(yīng)用字段名

  select distinct(col.column_name),r.table_name,r.column_name

  from

  user_constraints con,

  user_cons_columns col,

  (select t2.table_name,t2.column_name,t1.r_constraint_name

  from user_constraints t1,user_cons_columns t2

  where t1.r_constraint_name=t2.constraint_name

  and t1.table_name='YourTableName'

  ) r

  where con.constraint_name=col.constraint_name

  and con.r_constraint_name=r.r_constraint_name

  and con.table_name='YourTableName'

  SQLServer中的實(shí)現(xiàn):

  字段:

  SELECT c.name,t.name,c.xprec,c.xscale,c.isnullable

  FROM systypes t,syscolumns c

  WHERE t.xtype=c.xtype

  AND c.id = (SELECT id FROM sysobjects WHERE name='YourTableName')

  ORDER BY c.colid

  主鍵(參考SqlServer系統(tǒng)存儲(chǔ)過(guò)程sp_pkeys):

  select COLUMN_NAME = convert(sysname,c.name)

  from

  sysindexes i, syscolumns c, sysobjects o

  where o.id = object_id('[YourTableName]')

  and o.id = c.id

  and o.id = i.id

  and (i.status & 0x800) = 0x800

  and (c.name = index_col ('[YourTableName]', i.indid,? 1) or

  c.name = index_col ('[YourTableName]', i.indid,? 2) or

  c.name = index_col ('[YourTableName]', i.indid,? 3) or

  c.name = index_col ('[YourTableName]', i.indid,? 4) or

  c.name = index_col ('[YourTableName]', i.indid,? 5) or

  c.name = index_col ('[YourTableName]', i.indid,? 6) or

  c.name = index_col ('[YourTableName]', i.indid,? 7) or

  c.name = index_col ('[YourTableName]', i.indid,? 8) or

  c.name = index_col ('[YourTableName]', i.indid,? 9) or

  c.name = index_col ('[YourTableName]', i.indid, 10) or

  c.name = index_col ('[YourTableName]', i.indid, 11) or

  c.name = index_col ('[YourTableName]', i.indid, 12) or

  c.name = index_col ('[YourTableName]', i.indid, 13) or

  c.name = index_col ('[YourTableName]', i.indid, 14) or

  c.name = index_col ('[YourTableName]', i.indid, 15) or

  c.name = index_col ('[YourTableName]', i.indid, 16)

  )

  外鍵:

  select t1.name,t2.rtableName,t2.name

  from

  (select col.name, f.constid as temp

  from syscolumns col,sysforeignkeys f

  where f.fkeyid=col.id

  and f.fkey=col.colid

  and f.constid in

  ( select distinct(id)

  from sysobjects

  where OBJECT_NAME(parent_obj)='YourTableName'

  and xtype='F'

  )

  ) as t1 ,

  (select OBJECT_NAME(f.rkeyid) as rtableName,col.name, f.constid as temp

  from syscolumns col,sysforeignkeys f

  where f.rkeyid=col.id

  and f.rkey=col.colid

  and f.constid in

  ( select distinct(id)

  from sysobjects

  where OBJECT_NAME(parent_obj)='YourTableName'

  and xtype='F'

  )

  ) as t2

  where t1.temp=t2.temp

關(guān)鍵詞標(biāo)簽:Oracle,SqlServer,sql

相關(guān)閱讀

文章評(píng)論
發(fā)表評(píng)論

熱門文章 Oracle中使用alter table來(lái)增加,刪除,修改列的語(yǔ)法 Oracle中使用alter table來(lái)增加,刪除,修改列的語(yǔ)法 oracle中使用SQL語(yǔ)句修改字段類型-oracle修改SQL語(yǔ)句案例 oracle中使用SQL語(yǔ)句修改字段類型-oracle修改SQL語(yǔ)句案例 誤刪Oracle數(shù)據(jù)庫(kù)實(shí)例的控制文件 誤刪Oracle數(shù)據(jù)庫(kù)實(shí)例的控制文件 為UNIX服務(wù)器設(shè)置Oracle全文檢索 為UNIX服務(wù)器設(shè)置Oracle全文檢索

相關(guān)下載

    人氣排行 oracle中使用SQL語(yǔ)句修改字段類型-oracle修改SQL語(yǔ)句案例 Oracle中使用alter table來(lái)增加,刪除,修改列的語(yǔ)法 ORACLE SQL 判斷字符串是否為數(shù)字的語(yǔ)句 ORACLE和SQL語(yǔ)法區(qū)別歸納(1) oracle grant 授權(quán)語(yǔ)句 ORACLE修改IP地址后如何能夠使用 如何加速Oracle大批量數(shù)據(jù)處理 Oracle刪除表的幾種方法