Displays information from all tables in SQL Server _mssql

Source: Internet
Author: User

Display information for all tables or views in a database in a SQL Server
The difference between SQL Server 2000 and 2005 is in the Red Word section
The following statement takes all table information and replaces the green bold word "U" as "V" for all View information.

SQL Server 2000 Version

SELECT Sysobjects.name as TABLE_NAME, syscolumns. Id, syscolumns.name as column_name,
Systypes.name as Data_type, syscolumns.length as Character_maximum_length,
Sysproperties. [Value] As Column_description, Syscomments.text as
Column_default,syscolumns.isnullable as is_nullable from syscolumns
INNER JOIN systypes
On syscolumns.xtype = Systypes.xtype
Left JOIN sysobjects on syscolumns.id = sysobjects.id
Left OUTER JOIN sysproperties on
(Sysproperties.smallid = Syscolumns.colid
and sysproperties.id = syscolumns.id)
Left OUTER JOIN syscomments on syscolumns.cdefault = syscomments.id
WHERE Syscolumns.id in
(SELECT ID from sysobjects WHERE xtype = ' U ') and (systypes.name <> ' sysname ')
ORDER BY Syscolumns.colid

SQL Server 2005 version

SELECT Sysobjects.name as table_name, syscolumns. Id, Syscolumns.name as column_name,
Systypes.name as Data_type, syscolumns.length as Character_maximum_length,
Sys.extended_properties. [Value] As column_description,  Syscomments.text as
Column_default,syscolumns.isnullable as IS_NULLABLE from syscolumns
INNER JOIN systypes
    on syscolumns.xtype = Systypes.xtype
    Left JOIN sysobjects on syscolumns.id = Sysobjects.id
   left OUTER JOIN sys.extended_properties on
&nbs p;  (sys.extended_properties.minor_id = Syscolumns.colid
     and Sys.extended_ properties.major_id = syscolumns.id)
   left OUTER JOIN syscomments on syscolumns.cdefault = syscomments.id
   where syscolumns.id in 
    (SELECT ID from sysobjects WHERE xtype = ' U ') and (s Ystypes.name <> ' sysname ')
    order by Syscolumns.colid


Reference: Http://www.devx.com/tips/Tip/31235?type=kbArticle&trk=MSCP

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.