Getting the Column Names with Datatypes of Table

September 14, 2005



>>Script Language and Platform: SQL Server
This script will give the Column names with datypes of a table. You can give tablename id for specific table.

Author: Sarang R Bobde


SELECT SYSOBJECTS.NAME AS [TableName], SYSCOLUMNS.NAME AS [Column Name],
SYSTYPES.NAME AS [Field Type], SYSCOLUMNS.Length,
CASE WHEN SYSCOLUMNS.isNullable= 0 THEN 'NOT NULL' ELSE 'NULL' 
END AS isNullable
FROM SYSOBJECTS INNER JOIN SYSCOLUMNS ON SYSOBJECTS.ID = SYSCOLUMNS.ID 
INNER JOIN SYSTYPES ON SYSTYPES.XTYPE = SYSCOLUMNS.XTYPE
WHERE OBJECTPROPERTY(SYSOBJECTS.id, N'IsUserTable') = 1
ORDER BY SYSOBJECTS.NAME 

Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers