Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get basic SQL Server table structure information

Tags:

sql

sql-server

I can get the number of columns in an SQL Server database with this:

SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'Address' 

But is there any way (for an unknown number of columns) I can get the name and datatype and length of each column?

like image 901
1252748 Avatar asked Feb 11 '13 20:02

1252748


People also ask

How do I find the structure of a table in SQL Server?

Using SQL Server Management Studio In Object Explorer, select the table for which you want to show properties. Right-click the table and choose Properties from the shortcut menu. For more information, see Table Properties - SSMS.

How can I find the details of a table?

SQL Server: sp_help table_name (or sp_columns table_name for only columns) Oracle DB2: desc table_name or describe table_name. MySQL: describe table_name (or show columns from table_name for only columns)

What is SQL command to view structure of table?

So desc or describe command shows the structure of table which include name of the column, data-type of column and the nullability which means, that column can contain null values or not. All of these features of table are described at the time of Creation of table.


1 Answers

Instead of using count(*) you can SELECT * and you will return all of the details that you want including data_type:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'Address' 

MSDN Docs on INFORMATION_SCHEMA.COLUMNS

like image 190
Taryn Avatar answered Oct 07 '22 13:10

Taryn