Sunday, 13 March 2011

Get the table schema from sql database


Use the following query to get the table schema from the sql database :

SELECT COLUMN_NAME,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,ORDINAL_POSITION
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'TableName'


This will show the column name with the datatype and maximum no character a column can contains in the table.