zoukankan      html  css  js  c++  java
  • 数据库文档编写辅助脚本

    当我向我们的dba拿数据库文档编写文档模板d时候,

    她给了我这个脚本。

    虽然没有达到我真正想要的,但是很不错。

      

    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
    WHERE D.NAME IN ('Station','AreaType','CityType','StationType')
    ORDER BY A.ID,A.COLORDER
    

      

  • 相关阅读:
    php_l3arning_notes_3
    php_l3arning_notes_2
    php_l3arning_notes_1
    从 HTTP 到 HTTPS 再到 HSTS
    WSGI&ASGI
    WSGI 介绍
    什么是multipart/form-data请求
    SSH 端口转发
    Redis与RabbitMQ作为消息队列的比较
    数据库索引,到底是什么做的?
  • 原文地址:https://www.cnblogs.com/hillgisman/p/4234069.html
Copyright © 2011-2022 走看看