sql查詢表結構的語句
select
( case when a.colorder = 1 then d.name else '' end ) 表名,
a.colorder 字段序號,
a.name 欄位名,
( case when columnproperty (a.id,a.name,'isidentity') = 1 then '√' else '' end ) 標識,
( 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 ) 主鍵,
b.name 型別,
a.length 位元組數, columnproperty ( a.id,a.name ,'precision' ) as 長度,
isnull ( columnproperty ( a.id,a.name ,'scale'),0) as 小數字數,
(case when a.isnullable = 1 then '√' else '' end ) 允許空,
isnull ( e.text,'') 預設值,
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 sysproperties g
on a.id = g.id and a.colid = g.**allid
where d.name='tb_latency_cust'----寫上自己要查詢的表名
order by a.id ,a.colorder
Sql 語句查詢表結構
sql2000系統表的應用 1 獲取當前資料庫中的所有使用者表 select name from sysobjects where xtype u and status 0 2 獲取某乙個表的所有字段 select name from syscolumns where id object id 表名...
查詢表結構的SQL語句
如果需要查詢表結構,sql語句能否實現呢?下面就將為您介紹查詢表結構的sql語句的寫法,希望對您學習sql語句能夠有所幫助。查詢非系統資料庫 select name from master.sysdatabases where dbid 4 選擇water資料庫下的所有表 use water sel...
SQL SERVER 查詢表結構的SQL語句
select case whena.colorder 1thend.name else end as 表名,如果表名相同就返回空 syscolumns 表字段資訊表 a sysobjects d a colorder as欄位序號,a.name as欄位名,case when columnprope...