獲得SQLSERVER的表字段等架構資訊

2022-02-21 02:37:47 字數 1531 閱讀 3087

獲得sqlserver的表字段等架構資訊

select

表名 = case when a.colorder=1 then d.name else '' end,

表說明 = case when a.colorder=1 then 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 1 from 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=1 then '√'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=0

order by

a.id,a.colorder

表字段的處理 Sql Server

目錄 表的建立 建立約束 檢視約束 刪除約束 插入資料 增加字段 刪除字段 create table student 學號 char 8 not null,姓名 char 8 not null,性別 char 2 not null,出生日期 date default getdate 班級 char ...

sql server 刪除表字段和字段的約束

刪除資料庫表中的字段時,使用了 alter table 表名 drop column 列名 伺服器返回的錯誤為 server msg 5074,level 16,state 1,line 1 the object 約束名 is dependent on column 列名.server msg 49...

對Sql Server表字段進行修改

通用式 alter table 表名 add 欄位名 字段屬性 default 預設值 default 是可選引數 增加字段 alter table 表名 add 欄位名 smallint default 0 增加數字字段,整型,預設值為0 alter table 表名 add 欄位名 int de...