由於寫乙個**自動生成工具,需要找一些讀系統資料字典的資訊,
以前有個寫乙個很不錯的,
case
when
a.colorder=1
then
d.name
else
''end
, 字段序號
=a.colorder, 欄位名
=a.name, 標識
=case
when
columnproperty
( a.id,a.name,
'isidentity')
=1then'√
'else
''end
, 主鍵
=case
when
exists
(select
1from
sysobjects
where
xtype='
pk'andname
in(
select
name
from
sysindexes
where
indid
in(
select
indid
from
sysindexkeys
where
id =
a.id
andcolid
=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=1
then'√
'else
''end
, 預設值
=isnull
(e.text,''
), 字段說明
=isnull
(g.[
value],
'')from
syscolumns a
left
join
systypes b
ona.xtype
=b.xusertype
inner
join
sysobjects d
ona.id
=d.id
andd.xtype='
u'andd.name
<>
'dtproperties
'left
join
syscomments e
ona.cdefault
=e.id
left
join
sysproperties g
ona.id
=g.id
anda.colid
=g.smallid
order
bya.id,a.colorder
我也按字的方法來讀,
但是今天發現,主鍵,資訊不是很正確,
一看**,讀主鍵,那要跟索引結合起來的,
於是上網找相關資料,找了半天,也沒有找到,
於是就自己看sql server的幫助,
最後發現,
syscolumns的status為128就是主鍵,
columnname
=a.name, type
=b.name,length3
=columnproperty
(a.id,a.name,
'precision
'),
=case
a.status
when
128then'1
'else'0
'end
, length1
=a.length, length2
=isnull
(columnproperty
(a.id, a.name,
'scale
'),
0),isidentity
=case
when
columnproperty
(a.id, a.name,
'isidentity
') =1
then'1
'else'0
'end
from
syscolumns a
left
join
systypes b
ona.xtype
=b.xusertype
inner
join
sysobjects d
ona.id
=d .id
andd .xtype ='
u'andd .name
<>
'dtproperties
'left
join
syscomments e
ona.cdefault
=e.id
left
join
sysproperties g
ona.id
=g.id
anda.colid
=g.smallid
where
d .name ='
users
'order
bya.id, a.colorder
幾個常用的,對錶的某一列進行操作的SQL命令
適用 oracle 修改列名 alter table rename column aaa to bbb 刪除一列 alter table drop column aaa 增加一列 alter table add aaa varchar2 22 修改某列的型別 alter table modify a...
sql 給表某一列的全部資料追加相同的資料
testsql 表 age 列名 column limit 1 追加的資料 ps oracle中 1 給testsql表的所有記錄的age欄位裡面追加 limit 1內容 update testsql set age concat age,limit 1 2 將剛才追加內容刪除 update tes...
如何在SQL中去重某一列的重複值顯示所有的資料
現有一張表如上 content列有乙個重複的資料,我想去掉一條 不考慮其他列 顯示成下面的結果 select from t xf care education where id in select min id from t xf care education group by content 格式...