SQL Server self-built process for viewing table structure

Source: Internet
Author: User

Self-built process for viewing table structure

CREATE PROC [Sp_tablehelp](@TableName VARCHAR( -)= "',@ColName VARCHAR( -)="') asBEGIN        --table structure Quick Check        --Brin        --DECLARE @TableName VARCHAR (+)        --DECLARE @ColName VARCHAR (+)            --SET @TableName = ' Tlocatormove '        --SET @ColName = ' Nstatus '        SELECTTableName=( Case  whenCol.colorder= 1 OR @TableName  is NULL  ThenObj.nameELSE "' END), Colorder=Col.colorder, ColName=Col.name, Coldescription= ISNULL(Ep.value,"'), Coltype=T.name, Collength=Col.length, Colscale= ISNULL(ColumnProperty(Col.id, Col.name,' Scale'),0), Colisidentity=( Case  when ColumnProperty(Col.id, Col.name,'isidentity')= 1  Then '√' ELSE "' END), COLISPK=( Case  when EXISTS(SELECT 1  fromsys.sysindexes siJOINSys.sysindexkeys Sik onSi.id=Sik.id andSi.indid=Sik.indidJOINSys.syscolumns SC onSc.id=Sik.id andSc.colid=Sik.colidJOINSys.sysobjects so onSo.name=Si.name andSo.xtype= 'PK'                                           WHERESc.id=Col.id andSc.colid=Col.colid) Then '√'                           ELSE "' END), Colisnull=( Case  whenCol.isnullable= 1  Then '√' ELSE "' END), Coldefaultvalue= ISNULL(Comm.text,"')         fromSys.syscolumns Col Left  JOINSys.systypes T onCol.xtype=T.xusertypeINNER JOINSys.sysobjects obj onCol.id=Obj.id andObj.xtype= 'U'  andObj.status>= 0  and(Obj.name= @TableName OR ISNULL(@TableName,"')="' )         Left  JOINSys.syscomments Comm onCol.cdefault=comm.id Left  JOINSys.extended_properties EP onCol.id=ep.major_id andCol.colid=ep.minor_id andEp.name= 'ms_description'           Left  JOINSys.extended_properties Eptwo onObj.id=eptwo.major_id andeptwo.minor_id= 0  andEptwo.name= 'ms_description'          WHERE  1=1          and(Col.name= @ColName OR ISNULL(@ColName,"')="')        ORDER  byObj.name,col.colorder; END 

SQL Server self-built process for viewing table structure

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.