Getting the Column Names with Datatypes of Table

>>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

Get the Free Newsletter!

Subscribe to Cloud Insider for top news, trends & analysis

Latest Articles