SQL Server 基础知识回顾

背景:工作调整,由mysql转到sql server,从今天开始学习,进行知识储备。

  1. sql server查询数据库表结构说明
     1 -- 数据字典
     2 SELECT
     3         (case when a.colorder=1 then d.name else ‘‘ end)表名,
     4         a.colorder 字段序号,
     5         a.name 字段名,
     6         (case when COLUMNPROPERTY( a.id,a.name,IsIdentity)=1 then else ‘‘ end) 标识,
     7        (case when (SELECT count(*)
     8         FROM sysobjects
     9         WHERE (name in
    10                 (SELECT name
    11                 FROM sysindexes
    12                 WHERE (id = a.id) AND (indid in
    13                          (SELECT indid
    14                         FROM sysindexkeys
    15                         WHERE (id = a.id) AND (colid in
    16                                   (SELECT colid
    17                                  FROM syscolumns
    18                                  WHERE (id = a.id) AND (name = a.name))))))) AND
    19             (xtype = PK))>0 then  else ‘‘ end) 主键,
    20        b.name 类型,
    21        a.length 占用字节数,
    22       COLUMNPROPERTY(a.id,a.name,PRECISION) as 长度,
    23       isnull(COLUMNPROPERTY(a.id,a.name,Scale),0) as 小数位数,
    24       (case when a.isnullable=1 then else ‘‘ end) 允许空,
    25       isnull(e.text,‘‘) 默认值,
    26       isnull(g.[value],‘‘) AS 字段说明
    27 FROM  syscolumns  a left join systypes b
    28 on  a.xtype=b.xusertype
    29 inner join sysobjects d
    30 on a.id=d.id  and  d.xtype=U and  d.name<>dtproperties
    31 left join syscomments e
    32 on a.cdefault=e.id
    33 left join sys.extended_properties g
    34 on a.id=g.major_id AND a.colid = g.major_id
    35 order by a.id,a.colorder,表名

     

SQL Server 基础知识回顾

上一篇:JDBC


下一篇:数据库设计:表的设计命名的十个注意点