Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Apr 17, 2006

Display Table Information

This script displays all your table names—along with their column names, data types, data lengths, and null/not null information in a database.

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
Neeraj Tyagi
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap