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

2021-09-01 04:53:45 字數 4109 閱讀 6958

一、oracle

1、獲取當前oracle資料庫中的所有表

select table_name from user_tables

2、查詢某個表中的欄位名稱、型別、精度、長度、是否為空

select column_name,data_type,data_precision,data_scale,nullable

from user_tab_columns

where table_name ='yourtablename'

3、查詢某個表中的主鍵欄位名

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'

4、查詢某個表中的外來鍵欄位名稱、所引用表名、所應用欄位名

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'

5、如何從oracle中取得表的注釋

user_tab_comments;表注釋

user_col_comments;表字段注釋

以上兩個只能獲取自己使用者的表的注釋資訊,如果要訪問自己

能夠訪問的其他使用者的表,則需要使用:

all_tab_comments;表注釋

all_col_comments;表字段注釋

當然,如果有dba許可權,則可以使用

dba_tab_comments;表注釋

dba_col_comments;表字段注釋

dba*和all*最好指定owner條件。user*沒有該欄位

user_tab_comments;表注釋

user_col_comments;表字段注釋

二、sqlserver

1、讀取庫中的所有表名

select name from sysobjects where xtype='u'

2、字段

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

3、主鍵(參考sqlserver系統儲存過程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)

) 4、外來鍵

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

三、access

1、所有表清單

conn.open();

dt= conn.getoledbschematable(oledbschemaguid.tables, new object );

2、表結構

conn.open();

dtcolumnsinfo = conn.getoledbschematable(oledbschemaguid.columns, new object );

Mysql修改字段型別,欄位名

mysql修改字段型別 alter table 表名 modify column 欄位名 新資料型別 新型別長度 新預設值 新注釋 column可以省略 alter table table1 modify column column1 decimal 10,1 default null commen...

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

sql 檢視所有表名 select name from sysobjects where type u 查詢表的所有欄位名 select name from syscolumns where id object id 表名 select from information schema.tables ...

Mysql修改字段型別,修改欄位名

mysql修改字段型別 能修改字段型別 型別長度 預設值 注釋 對某欄位進行修改 alter table 表名 modify column 欄位名 新資料型別 新型別長度 新預設值 新注釋 column可以省略 alter table table1 modify column column1 dec...