declare@columnname
asvarchar(100
);set
@columnname='
欄位名的模糊匹配';
select表名=
d.name,
表說明
=case
when a.colorder=
1then
isnull(f.value, '
') else''
end,
字段序號
=a.colorder,
欄位名
=a.name,
標識
=case
when
columnproperty( a.id,a.name, '
isidentity
')=1
then'√
'else''
end,
主鍵 =
case
when
exists(select
1from sysobjects where xtype=
'pk
'and parent_obj=a.id and name in
(
select name from sysindexes where indid in
(
select indid from sysindexkeys where id = a.id and colid=a.colid))) then'√
'else''
end,
型別 =
b.name,
占用位元組數
=a.length,
長度 =
columnproperty(a.id,a.name, '
precision
'),
小數字數
=isnull(columnproperty(a.id,a.name, '
scale
'),0
),
允許空
=case
when a.isnullable=
1then'√
'else''
end,
預設值
=isnull(e.text, '
'),
字段說明
=isnull(g.[
value
], '
')
from syscolumns a left
join systypes b on a.xusertype=
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
left
join sys.extended_properties f on d.id=f.major_id and f.minor_id=
0where a.name like
@columnname
andright(d.name,3)<>
'log
'order
by a.id,a.colorder
posted @
2019-03-25 11:37
jinweichang 閱讀(
...)
編輯收藏
sqlserver2005查詢字段資訊
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 ...
sql server 查詢欄位上的約束
1.當欄位沒有預設值或者約束的時候可以使用 alter table table name drop column column name 來刪除。當有預設值的時候應該先刪除預設值,然後再刪除此列,不然會報錯。具體方法如下 select b.name from sysobjects b join sy...
sql查詢字段連線
我有乙個需求是把2個字段拼接成乙個字段,如 user user id,user code,user name 查詢結果是 user code user name 在寫sql語句時用連線符 select user code user name codename from user 上面這種寫法是ora...