SQL查表名 欄位名 表說明 字段說明

2021-05-22 11:07:41 字數 3150 閱讀 4107

sql 檢視所有表名:

select name from sysobjects where type='u'

查詢表的所有欄位名:

select name from syscolumns where id=object_id('表名')

select * from information_schema.tables

select * from information_schema.views

select * from information_schema.columns

access

檢視所有表名:

select name from msysobjects where type=1 and flags=0

msysobjects是系統物件,預設情況是隱藏的。通過工具、選項、檢視、顯示、系統物件可以使之顯示出來。

sql查詢表的備註說明

select 表名 = case when a.colorder = 1 then d.name

else '' end,

表說明 = case when a.colorder = 1 then isnull(f.value, '')

else '' end

from syscolumns a

inner join sysobjects d

on a.id = d.id

and d.xtype = 'u'

and d.name <> 'sys.extended_properties'

left join sys.extended_properties   f

on a.id = f.major_id

and f.minor_id = 0

sql查詢表的所有欄位的備註說明

sql_1:

select sysobjects.name as table_name, syscolumns.id, syscolumns.name as column_name,

systypes.name as data_type, syscolumns.length as character_maximum_length,

sys.extended_properties.[value] as column_description,  syscomments.text as

column_default,syscolumns.isnullable as is_nullable from syscolumns

inner join systypes

on syscolumns.xtype = systypes.xtype

left join sysobjects on syscolumns.id = sysobjects.id

left outer join sys.extended_properties on

( sys.extended_properties.minor_id = syscolumns.colid

and sys.extended_properties.major_id = syscolumns.id)

left outer join syscomments on syscolumns.cdefault = syscomments.id

where syscolumns.id in

(select id from sysobjects where xtype = 'u') and (systypes.name <> 'sysname')

order by syscolumns.colid

sql_2:

select

(case when a.colorder=1 then d.name else '' end) n'表名',

a.colorder n'字段序號',

a.name n'欄位名',

(case when columnproperty( a.id,a.name,'isidentity')=1 then '√'else ''

end) n'標識',

(case when (select count(*)

from sysobjects

where (name in

(select name

from sysindexes

where (id = a.id) and (indid in

(select indid

from sysindexkeys

where (id = a.id) and (colid in

(select colid

from syscolumns

where (id = a.id) and (name = a.name))))))) and

(xtype = 'pk'))>0 then '√' else '' end) n'主鍵',

b.name n'型別',

a.length n'占用位元組數',

columnproperty(a.id,a.name,'precision') as n'長度',

isnull(columnproperty(a.id,a.name,'scale'),0) as n'小數字數',

(case when a.isnullable=1 then '√'else '' end) n'允許空',

isnull(e.text,'') n'預設值',

isnull(g.[value],'') as n'字段說明'

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' and d.name<>'dtproperties'

left join syscomments e

on a.cdefault=e.id

left join sys.extended_properties g

on a.id=g.major_id and a.colid = g.minor_id

order by object_name(a.id),a.colorder

SQL 更新表名,欄位名語句

修改表名 exec sp rename 原表名 新錶名 修改欄位名 exec sp rename 表名 欄位名 新欄位名 新增字段 alter table 表名 add 列名 字段型別 如果欄位不為空,需要先新增乙個預設值 alter table 表名 add 列名 字段型別 not null de...

查表的欄位名,主鍵,字段型別

一 oracle 1 獲取當前oracle資料庫中的所有表 select table name from user tables 2 查詢某個表中的欄位名稱 型別 精度 長度 是否為空 select column name,data type,data precision,data scale,nu...

根據字段值 查詢 欄位名,表名

declare what varchar 800 set what bffc43e1 6646 434e b47d 0a32ac793b1c 要搜尋的字串 declare sql varchar 8000 declare tablecursor cursor local for select sql...