資料庫,表,字段,型別等查詢

2022-02-26 14:42:11 字數 2651 閱讀 7749

--獲取所有資料庫名

select name from master..sysdatabases order by name

--獲取所有表名 xtype='u':表示所有使用者表; xtype='s':表示所有系統表;

select name from [gwi-pay]..sysobjects where xtype='u' order by name

--獲取表中的欄位名

select name from syscolumns where id=object_id('order')

--獲取數庫所有字段型別

select name from systypes

--獲取主鍵字段

select name from syscolumns where id=object_id('order') and colid=(select top 1 keyno from sysindexkeys where id=object_id('order'))

--獲取字段型別

select a.name as [column],b.name as type from syscolumns a,systypes b where a.id=object_id('order') and a.xtype=b.xtype

--獲取表結構 欄位名 型別 長度

select column_name,data_type,character_maximum_length from information_schema.columns where table_name = 'order'

--

查詢表的整體架構

select

d.name

as tablename,--

表名 a.colorder as fieldorder,--

字段序號

a.name as

fieldname,

(case

when

columnproperty( a.id,a.name, '

isidentity

' )=

1then'y

'else'n

'end) as isidentity,--

標識 (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

' ))>

0then'y

'else'n

'end) as isprimarykey,--

查詢主鍵end

b.name as fieldtype, --

型別a.length as bytelength,--

位元組數

columnproperty(a.id,a.name,'

precision

' ) as

fieldlength,

isnull(columnproperty(a.id,a.name,'

scale

' ),0) as radixpoint,--

小數字數,

(case

when a.isnullable=

1then'y

'else'n

'end) as isnullable,--

是否允許空,

isnull(e.text,'' ) as defaultvalue,--

預設值

isnull(g.[

value

],'' ) as fielddesc --

字段說明

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

where d.name=

'code'--

所要查詢的表

order

by a.id,a.colorder

修改Oracle資料庫表字段型別

修改user表的name欄位型別從varchar2改為clob 1.新增乙個備份字段 alert table user add name back clob 2.複製name的值到備份欄位name back update user set name back name 3.刪除原來的字段user a...

MYSQL資料庫表字段型別(一)

整數型別 浮點數型別和定點數型別 日期與時間型別 鏈結 字串型別 二進位制字串型別 數值型別主要用來儲存數字,mysql提供了多種數值資料型別,不同的資料型別提供了不同的取值範圍,可以儲存的值範圍越大,其所需要的儲存空間也會越大。型別名稱 說明儲存需求 tinyint 很小的整數 1位元組small...

MYSQL資料庫表字段型別(二)

文字字串型別 鏈結 整數型別,浮點數型別和定點型別 二進位制字串型別 字串型別用來儲存字串資料,除了可以在儲存字串資料之外,還可以儲存其他資料,比如和聲音的二進位制資料。mysql還支援兩類字元型資料 文字字串型別。文字字串二進位制字串 表一型別名稱 說明儲存需求 char m 固定長度非二進位制字...