Profile

Monday 30 May 2011

SQL: Display attributes of a table.

When I need to create a table, I usually look for a existing table as a reference. We can use a query to pull only the attributes such as data type, column name and other information from a table:

For a full list of information you could pull from a table, please check out this link:
http://msdn.microsoft.com/en-us/library/ms188348.aspx

     USE AdventureWorks2008;
     GO
     SELECT COLUMN_NAME 'Column Name',
     DATA_TYPE 'Data Type',
     CHARACTER_MAXIMUM_LENGTH 'Maximum Length',
     IS_NULLABLE 'Nullable'
     FROM AdventureWorks2008.INFORMATION_SCHEMA.COLUMNS
     WHERE TABLE_NAME = 'Person';
     GO