sql server 查詢資料庫所有的表名 字段

2021-10-04 05:23:06 字數 3021 閱讀 6587

select * from information_schema.columns where table_name=『account』

select

(case when a.colorder=1 then d.name else 『』 end) as 表名,–如果表名相同就返回空

a.colorder as 字段序號,

a.name as 欄位名,

(case when columnproperty( a.id,a.name,『isidentity』)=1 then 『√』else 『』 end) as 標識,

(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) as 主鍵,–查詢主鍵end

b.name as 型別,

a.length as 占用位元組數,

columnproperty(a.id,a.name,『precision』) as 長度,

isnull(columnproperty(a.id,a.name,『scale』),0) as 小數字數,

(case when a.isnullable=1 then 『√』else 『』 end) as 允許空,

isnull(e.text,』』) as 預設值,

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

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 a.id,a.colorder

查詢資料庫裡所有表名和欄位名的語句

sql 查詢所有表名:

select name from sysobjects where type=『u』

select * from information_schema.tables

查詢表的所有欄位名:

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

select * from information_schema.tables

select * from information_schema.views

select * from information_schema.columns

oracle 檢視所有表名:

select table_name from user_tables

access 檢視所有表名:

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

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

字段型別

中文說明

限制條件

其它說明

char

固定長度字串

最大長度2000 bytes

varchar2

可變長度的字串

最大長度4000 bytes

可做索引的最大長度749

nchar

根據字符集而定的固定長度字串

最大長度2000 bytes

nvarchar2

根據字符集而定的可變長度字串

最大長度4000 bytes

date

日期(日- 月- 年)

dd-mm-yy (hh-mi-ss )

經過嚴格測試,無千蟲問題

long

超長字串

最大長度 2g (231 -1 )

足夠儲存大部頭著作

raw固定長度的二進位制資料

最大長度2000 bytes

可存放多**圖象聲音等

long raw

可變長度的二進位制資料

最大長度 2g

同上blob

二進位制資料

最大長度 4g

clob

字元資料

最大長度 4g

nclob

根據字符集而定的字元資料

最大長度 4g

bfile

存放在資料庫外的二進位制資料

最大長度 4g

rowid

資料表中記錄的唯一行號

10 bytes *******..格式, 為0 或1

nrowid

二進位制資料表中記錄的唯一行號

最大長度4000 bytes

number(p,s)

數字型別

p 為整數字,s 為小數字

decimal(p,s)

數字型別

p 為整數字,s 為小數字

integer

整數型別

小的整數

float

浮點數型別

number(38) ,雙精度

real

實數型別

number(63) ,精度更高

SQL Server資料庫查詢

開啟我們的sql server資料庫,找到要查詢的資料庫表,右鍵單擊然後選擇新建查詢,select 選擇我們要查詢的表sys academe學院表 聯合 sys class.classname班級表的班級名稱和sys grade.gradename年級表的年級編號來查詢出資料。下面是查詢的 sele...

SQL Server 跨資料庫查詢

語句 select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field dbo 可以省略 如 select from 資料庫a.表a a,資料庫b.表b b where a.field b.field sqlserver資料庫 這句是對映乙個...

查詢SQL SERVER 資料庫版本

select substring cast serverproperty productversion as nvarchar 128 1,charindex cast serverproperty productversion as nvarchar 128 1 1 8 對應 sql server...