SQL Query to display the columns and data types in all the tables

SQL Query to display the columns and data types in all the tables

The below mentioned script will display the details in the order of TableName, ColPosition, ColumnName, DataType and Length:

SELECT
IT.TABLE_NAME AS ‘TableName’,
ORDINAL_POSITION AS ‘ColPosition’,
COLUMN_NAME AS ‘ColumnName’,
DATA_TYPE AS ‘DataType’,
CHARACTER_MAXIMUM_LENGTH AS ‘Length’
from INFORMATION_SCHEMA.COLUMNS as IC
inner join INFORMATION_SCHEMA.TABLES as IT on  IT.TABLE_NAME=IC.TABLE_NAME and IT.TABLE_TYPE=’BASE TABLE’
ORDER BY
TableName,
ColPosition

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: