--查詢所有使用者表所有欄位的特徵
select d.name
as tablename, a.colorder
as colorder, a.name
as name,
columnproperty(a.id,a.name,
'isidentity
') as isidentity,
case
when
exists
( select
1
from dbo.sysobjects
where xtype
='pk
'and name
in( select name
from sysindexes
where indid
in( select indid
from sysindexkeys
where id
= a.id
and colid
= a.colid)))
then
1
else
0
endas 主鍵,
b.name
as 型別,
a.length
as[長度
],
a.xprec
as[精度
],
a.xscale
as[小數
],
case
when a.isnullable
=1
then
1
else
0
endas[
可為空],
isnull(e.
text,
'') as
[預設值
],
isnull(g.
[value
], '
') as[說明
]from dbo.syscolumns a
left
outer
join
dbo.systypes b
on a.xtype
= b.xusertype
inner
join
dbo.sysobjects d
on a.id
= d.id
and d.xtype
='u'and
d.name
<>
'dtproperties
'left
outer
join
dbo.syscomments e
on a.cdefault
= e.id
left
outer
join dbo.sysproperties g
on a.id
= g.id
and a.colid
= g.smallid
--where d.name='tablename' --如果找指定表,把注釋去掉
order
by1,
2
------在sqlserver 2005中測試
--查詢所有使用者表所有欄位的特徵
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
--where d.name='pe_u_vallimessage' --所要查詢的表
order
by a.id,a.colorder
資料庫修改表名,欄位名 字段型別
修改表 1 修改表的名稱呢 alter table 表名 rename to 新的名字 demo alter table ta1 rename to ta0 2 新增乙個新字段 alter table 表名 add 新字段 欄位的型別 demo alter table ta0 add unames ...
ASP獲取資料庫表名,欄位名
在asp論壇上看到很多問怎麼獲取資料庫表名,欄位名以及如何對欄位進行刪除,增添的操作故寫此文。本人對sqlserver比較熟一些,故以sqlserver為列 set conn server.createobject adodb.connection conn.open server ip位址 pro...
獲取oracle資料庫的表名 欄位名等系統資訊
獲取oracle表和資料庫欄位時,需要用到的表 獲取表 select table name from user tables 當前使用者名稱下的表的資訊 select table name from all tables 當前使用者有許可權的表的資訊 只要對某個表有任何許可權,即可在此檢視中看到表的...