SQL Server database dictionary to generate SQL

SQL Server database dictionary to generate SQL

 

SELECT table name =  the CASE  
                 the WHEN a.colorder =  . 1  THEN d.name
                  the ELSE       '' 
            the END ,
        - table illustrates = case when a.colorder = 1 then isnull (f.value, '') else '' end, 
       the field number                                 = a.colorder,
       Field description                                 =  ISNULL (g. [ Value ] , '' ),
       Field name                                  = 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 NAME IN (SELECT NAME
                                              FROM   sysindexes
                                              WHERE  indid IN (SELECT indid
                                                               FROM   sysindexkeys
                                                               WHERE  id = a.id
                                                                      AND colid = a.colid))
                      ) THEN ''
                 ELSE      ''
            END,
       Type = b.name,
       Occupied bytes = a.length,
       Length =  COLUMNPROPERTY (a.id, a.name, ' PRECISION ' ),
       Decimal places =  ISNULL ( COLUMNPROPERTY (a.id, a.name, ' Scale ' ), 0 ),
       Allow empty =  CASE  
                  WHEN a.isnullable =  1  THEN  ' ' 
                  ELSE      '' 
             END ,
       默认值 = ISNULL(e.text, '')
FROM   syscolumns a
       LEFT JOIN systypes b
            ON  a.xtype = 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 =  ' tk_ticketVisaFee '  - If only the specified table query, add this condition 
the ORDER  BY
       a.id,
       a.colorder

 

 

Guess you like

Origin www.cnblogs.com/Sabre/p/12697526.html