返回列表 发帖

学会使用数据库字典

当表建立之后,很长时间,很容易会忘记表名,
而其实数据库中是存在一种叫数据字典的东西方便我们查询的,
只要知道,表中的一列或注释,就可以很轻松的查到表中的表名,和其他相关信息
1.根据表名所含字符查表名
Select Dt.Owner      所有者
   ,Dt.Table_Name 表名
   ,Dtc.Comments  注释
From Dba_Tab_Comments Dtc
   ,Dba_Tables       Dt
Where Dt.Table_Name Like UPPER('Student_i%') --表名
-- And Dt.Owner = 'Fetch' --所有者
  And Dt.Owner = Dtc.Owner
  And Dt.Table_Name = Dtc.Table_Name
Order By Dt.Table_Name
   
2.根据表注释查表名
Select Dt.Owner      所有者
   ,Dt.Table_Name 表名
   ,Dtc.Comments  注释
From Dba_Tab_Comments Dtc
   ,Dba_Tables       Dt
Where Dtc.Comments Like '学生%' --表注释所含字符
-- And Dt.Owner = 'Fetch' --所有者
  And Dt.Owner = Dtc.Owner
  And Dt.Table_Name = Dtc.Table_Name
Order By Dt.Table_Name

3.根据字段名查表名
Select Dt.Owner        所有者
   ,Dt.Table_Name   表名
   ,Dcc.Column_Name 字段名
   ,Dcc.Comments    字段注释
   ,Dtc.Comments    表注释
From Dba_Tab_Comments Dtc
   ,Dba_Tables       Dt
   ,Dba_Col_Comments Dcc
Where Dcc.Column_Name Like '%STUDENT_ID%' --字段名
  And Dt.Owner = 'Fetch' --所有者
  And Dt.Owner = Dtc.Owner
  And Dt.Table_Name = Dtc.Table_Name
  And Dcc.Table_Name = Dt.Table_Name
  And Dcc.Owner = Dt.Owner
Order By Dt.Table_Name

4.根据字段注释名查表名
Select Dcc.Column_Name 字段名
   ,Dcc.Comments    字段注释
   ,Dt.Table_Name   表名
   ,Dtc.Comments    表注释
   ,Dt.Owner        所有者
From Dba_Tab_Comments Dtc
   ,Dba_Tables       Dt
   ,Dba_Col_Comments Dcc
Where Dcc.Comments Like '%%' --表注释所含字符
  And Dt.Owner = 'Fetch' --所有者
  And Dt.Owner = Dtc.Owner
  And Dt.Table_Name = Dtc.Table_Name
  And Dcc.Table_Name = Dt.Table_Name
  And Dcc.Owner = Dt.Owner
Order By Dt.Table_Name

TOP

生命没有假期!
如果生命只剩下最后一秒,你可会想到我?

TOP

TOP

返回列表