How to Get Table information in SQL Server like Column Name, Data Type, Character length, Default Values etc
How to Get Table information in SQL Server like Column Name, Data Type, Character length, Default Values etc
Through this article, we can get all the information of table like column name. , data type, length and so on. Many times we have needed to update the old database table. That time we forgot the datatype column name, default values and, Character length.
First Method:
SELECT *
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'info_table'
Out-Put:-
We can also use this alternative method to get Table information in SQL Server
Second Method:
sp_Columns 'info_table'
Out-Put:-
We get all below fields using the above query
TABLE_CATALOG,TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,ORDINAL_POSITION,COLUMN_DEFAULT,IS_NULLABLE,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,CHARACTER_OCTET_LENGTH,NUMERIC_PRECISION,NUMERIC_PRECISION_RADIX,NUMERIC_SCALE,DATETIME_PRECISION,CHARACTER_SET_CATALOG,CHARACTER_SET_SCHEMA,CHARACTER_SET_NAME,COLATION_CATALOG,COLLATION_SCHEMA,COLLATION_NAME,DOMAIN_CATALOG,DOMAIN_SCHEMA,DOMAIN_NAME
Suppose we want some specific fields information of a particular table then we can use below query here I have fetched only table name, column name, and datatype.
SELECT TABLE_NAME,COLUMN_NAME,DATA_TYPE
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'info_table'
How to Get Table information in SQL Server like Column Name, Data Type, Character length, Default Values etc
Reviewed by NEERAJ SRIVASTAVA
on
8:43:00 PM
Rating:
No comments: