Technical Article

Get the Table Structure using a simple query

,

This query will solve problems related to Table structure. Using this query you can have the complete table structure for all the user tables with Table Name, Column Name, Data Type, and Null attributes of a column.
You can run this script in Query Analyzer or make use of it in your front-end to give table structure to your Colleagues or documentation people.

Mohit Nayyar
MCP (.Net), MCSD, MCDBA

SELECT o.name Table_Name, c.name Column_Name, t.name DataType, c.Length, CASE WHEN c.isnullable=1 THEN   'Yes'   ELSE   'No'   END AS 'Nullable' 
FROM sysobjects o
INNER JOIN syscolumns c ON (o.id=c.id and o.type='U' and o.name not like 'dt%')
Inner Join systypes t ON (c.xtype=t.xtype) 
order by o.name, c.name

Rate

4.5 (2)

You rated this post out of 5. Change rating

Share

Share

Rate

4.5 (2)

You rated this post out of 5. Change rating