Development Experience

Thursday, September 20, 2012

Getting column information of a table



Getting column information of a table is very useful thing.
information_schema.columns contains this information.

I gonna use this code for one of my project. For this project I need all columns and their datatype etc.

You may use the following SQL to get column information of a specific table.


SELECT COLUMN_NAME,DATA_TYPE,IS_NULLABLE,CHARACTER_MAXIMUM_LENGTH
FROM   information_schema.columns
WHERE  table_name = 'TB_TERMINAL'
ORDER  BY ordinal_position

Also for other projects (may be you have one) it is better for you to modify this query like below to see other column information related with your table.

SELECT *
FROM   information_schema.columns
WHERE  table_name = 'TB_TERMINAL'
ORDER  BY ordinal_position


Good Luck

No comments:

Post a Comment