sql server export table structure to word

------ export table structure sentence
1, execute the following query

SELECT 
    table name        =  Case  When a.colorder = . 1  the then d.name the else  ''  End , 
    table illustrates      =  Case  When a.colorder = . 1  the then  ISNULL (f.value, '' ) the else  ''  End , 
    ID    = a.colorder , 
    column name      = a.name, 
    Chinese Remarks    =  ISNULL (G. [ value ] , '' ), 
    data type        =b.name, 
    length        =  the COLUMNPROPERTY (a.id, a.name, ' the PRECISION ' ), 
    decimals    =  ISNULL ( the COLUMNPROPERTY (a.id, a.name, ' Scale ' ), 0 ), 
    identifying        =  Case  When  the COLUMNPROPERTY (a.id, a.name, ' IsIdentity ' ) = . 1  the then  ' ' the else  ''  End , 
    the primary key        =  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,
    Occupies bytes = a.length, 
    allows null      =  Case  When a.isnullable = . 1  the then  ' a ' the else  ' NO '  End , 
    Default      =  ISNULL (E. Text , '' )
 the FROM 
    the syscolumns A 
left  the Join 
    the systypes B 
ON 
    A .xusertype = b.xusertype
 Inner  the Join 
    the 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='TableName'    --If only the specified table query, add this condition 
the Order  by 
    a.id, a.colorder

2, copied to Excel.

3, copied from Excel to the word in the document form.

 

2, copied to Excel.

3, copied from Excel to the word in the document form.

Guess you like

Origin www.cnblogs.com/fanqisoft/p/11915242.html
Recommended