SQL-各種數據庫中查看當前庫中所有表和字段信息

各種數據庫中查看當前庫中所有表和字段信息
2012-02-12 16:19

>>mysql :

1、查看所有表名:

show tables [from db_name];

2、查看字段信息

SHOW FULL COLUMNS FROM db_name.table_name

獲取以下信息

Field:字段名

Type:字段類型

Collation:字符集mysql 5.0以上有)

Null:是否可以爲NULL

Key:索引(PRI,unique,index)

Default:缺省值

Extra:額外(是否 auto_increment)

Privileges:權限

Comment:備註(mysql 5.0以上有)

>>sqlserver

1、查看所有用戶建表名

select name from Sysobjects where xtype='U' order by name;

2、查看字段信息

SELECT

a.colorder as字段順序號,

a.name as字段名稱,

a.collation as排序字符集,

是否自動增長數字=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 'yes'else 'no' end,

是否主鍵=case when exists(SELECT 1 FROM sysobjects where xtype='PK' and name in (

SELECT name FROM sysindexes WHERE indid in(

SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid

))) then 'yes' else 'no' end,

字段類型=b.name,

字段長度=a.length,

字段字符長度=COLUMNPROPERTY(a.id,a.name,'PRECISION'),

小數位數=isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),

是否爲NULL=case when a.isnullable=1 then 'yes'else 'no' end,

缺省值=isnull(e.text,'')

FROM syscolumns a

left join systypes b on a.xtype=b.xusertype

inner join sysobjects d on a.id=d.id and (d.xtype='U' or d.xtype='V') and d.name<>'dtproperties'

left join syscomments e on a.cdefault=e.id

where d.name='purchase_medicine'

order by a.colorder

>>oracle

//查詢所有表的信息

select * from dba_tables

//查詢所有視圖的信息

select * from dba_views

//查詢指定表或視圖的列信息

select * from dba_tab_columns

注意:當要創建包含Sys表空間的對象時,需要賦相應表或視圖的權限給它。

需要創建查詢包含表和視圖的視圖

create or replace view v_tableview

as

select owner , table_name from dba_tables

union all

select owner , view_name from dba_views

則需要

grant select on sys.dba_tables to "用戶"

grant select on sys.dba_views to "用戶"


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章