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

首頁 > 數據庫 > SQL Server > 正文

如何獲取MSSQLServer,Oracel,Access中的數據字典信息

2024-08-31 00:48:32
字體:
來源:轉載
供稿:網友

----------------------------------------------
--------------- ms sqlserver -----------------
----------------------------------------------

--表說明
select dbo.sysobjects.name as tablename,
      dbo.sysproperties.[value] as tabledesc
from dbo.sysproperties inner join
      dbo.sysobjects on dbo.sysproperties.id = dbo.sysobjects.id
where (dbo.sysproperties.smallid = 0)
order by dbo.sysobjects.name

--字段說明
select dbo.sysobjects.name as tablename, dbo.syscolumns.colid,
      dbo.syscolumns.name as colname, dbo.sysproperties.[value] as coldesc
from dbo.sysproperties inner join
      dbo.sysobjects on dbo.sysproperties.id = dbo.sysobjects.id inner join
      dbo.syscolumns on dbo.sysobjects.id = dbo.syscolumns.id and
      dbo.sysproperties.smallid = dbo.syscolumns.colid
order by dbo.sysobjects.name, dbo.syscolumns.colid

 

--主鍵、外鍵信息(簡化)
select
 c_obj.name    as constraint_name
 ,t_obj.name    as table_name
 ,col.name    as column_name
 ,case col.colid 
  when ref.fkey1 then 1   
  when ref.fkey2 then 2   
  when ref.fkey3 then 3   
  when ref.fkey4 then 4   
  when ref.fkey5 then 5   
  when ref.fkey6 then 6   
  when ref.fkey7 then 7   
  when ref.fkey8 then 8   
  when ref.fkey9 then 9   
  when ref.fkey10 then 10   
  when ref.fkey11 then 11   
  when ref.fkey12 then 12   
  when ref.fkey13 then 13   
  when ref.fkey14 then 14   
  when ref.fkey15 then 15   
  when ref.fkey16 then 16
 end      as ordinal_position
from
 sysobjects c_obj
 ,sysobjects t_obj
 ,syscolumns col
 ,sysreferences  ref
where
 permissions(t_obj.id) != 0
 and c_obj.xtype in ('f ')
 and t_obj.id = c_obj.parent_obj
 and t_obj.id = col.id
 and col.colid   in
 (ref.fkey1,ref.fkey2,ref.fkey3,ref.fkey4,ref.fkey5,ref.fkey6,
 ref.fkey7,ref.fkey8,ref.fkey9,ref.fkey10,ref.fkey11,ref.fkey12,
 ref.fkey13,ref.fkey14,ref.fkey15,ref.fkey16)
 and c_obj.id = ref.constid
union
 select
 i.name     as constraint_name
 ,t_obj.name    as table_name
 ,col.name    as column_name
 ,v.number    as ordinal_position
from
 sysobjects  c_obj
 ,sysobjects  t_obj
 ,syscolumns  col
 ,master.dbo.spt_values  v
 ,sysindexes  i
where
 permissions(t_obj.id) != 0
 and c_obj.xtype in ('uq' ,'pk')
 and t_obj.id = c_obj.parent_obj
 and t_obj.xtype  = 'u'
 and t_obj.id = col.id
 and col.name = index_col(t_obj.name,i.indid,v.number)
 and t_obj.id = i.id
 and c_obj.name  = i.name
 and v.number  > 0
  and v.number  <= i.keycnt
  and v.type  = 'p'

order by constraint_name, ordinal_position


--主鍵、外鍵對照(簡化)
select
 fc_obj.name   as constraint_name
 ,i.name     as unique_constraint_name
from 
 sysobjects fc_obj
 ,sysreferences r
 ,sysindexes i
 ,sysobjects pc_obj
where
 permissions(fc_obj.parent_obj) != 0
 and fc_obj.xtype = 'f'
 and r.constid  = fc_obj.id
 and r.rkeyid  = i.id
 and r.rkeyindid  = i.indid
 and r.rkeyid  = pc_obj.id


----------------------------------------------
------------------- oracle -------------------
----------------------------------------------

--表信息
select * from all_tab_comments t
where owner='dbo'

--列信息
select * from all_col_comments t
where owner='dbo'

--主鍵、外鍵對照
select owner, constraint_name, constraint_type, table_name, r_owner, r_constraint_name
from all_constraints
where owner='dbo' and (constraint_type='p' or constraint_type='r')


--主鍵、外鍵信息
select *
from all_cons_columns
where owner='dbo'
order by constraint_name, position


----------------------------------------------
------------------- access -------------------
----------------------------------------------
//access中的系統表msysobjects存儲屬性的字段是二進制格式,不能直接分析
//可以采用ado自帶的openschema方法獲得相關信息

  //use adoint.pas
  //po: tablename
  //dbcon:tadoconnection
  /ds:tadodataset
 
--表信息
  dbcon.openschema(sitables, vararrayof([null, null, 'table']), emptyparam, ds);

--列信息
  dbcon.openschema(sicolumns, vararrayof([null, null, 'po']), emptyparam, ds);
 
--主鍵
  dbcon.openschema(siprimarykeys, emptyparam, emptyparam, ds);
 
 
--主鍵、外鍵對照
  dbcon.openschema(siforeignkeys, emptyparam, emptyparam, ds);


 
  • 網站運營seo文章大全
  • 提供全面的站長運營經驗及seo技術!
  • 發表評論 共有條評論
    用戶名: 密碼:
    驗證碼: 匿名發表
    主站蜘蛛池模板: 黄平县| 丽江市| 启东市| 河南省| 会泽县| 方城县| 浏阳市| 余姚市| 泽州县| 临沧市| 沅江市| 平阴县| 沅江市| 荣昌县| 两当县| 象州县| 崇义县| 长寿区| 皮山县| 台江县| 巨鹿县| 依兰县| 玛多县| 黄梅县| 岳普湖县| 老河口市| 紫金县| 广汉市| 上饶市| 垦利县| 建水县| 平湖市| 闻喜县| 张家界市| 固始县| 冕宁县| 班戈县| 皋兰县| 鄯善县| 澄城县| 萨迦县|