Wednesday, June 29, 2011

How to get column properties from a table

How to get column properties from a table


You can get the columns detail of a table from the database.

SELECT t.name AS table_name,c.name AS column_name,c.is_identity,c.is_nullable,c.max_length,ty.name
AS TypeName FROM sys.Tables
t INNER JOIN sys.columns c ON t.OBJECT_ID = c.OBJECT_ID INNER JOIN sys.types ty ON c.user_type_id=ty.user_type_id

Using above query you can get table columns and columns properties like Column Name,
Data Type, Is Identity, Is Nullable, and Max Length.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.