Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T-SQL List Tables, Columns

In T-SQL (SQL Server 2000). How can I list all tables and columns in a database? Also, in a separate query is there a way to list all columns along with data type and constraints (NULLS, etc). Thanks.

like image 912
user1804387 Avatar asked May 15 '13 19:05

user1804387


People also ask

How do I list the columns in a table in SQL?

In a query editor, if you highlight the text of table name (ex dbo. MyTable) and hit ALT + F1 , you'll get a list of column names, type, length, etc.

How do I find the columns from all tables in a database?

USE YourDatabseName GO SELECT t.name AS table_name, SCHEMA_NAME(schema_id) AS schema_name, c.name AS column_name FROM sys. tables AS t INNER JOIN sys. columns c ON t. OBJECT_ID = c.


1 Answers

Please check out the information schema.

select * from MyDatabaseName.information_schema.columns order by table_name, ordinal_position 
like image 62
Tim Lehner Avatar answered Sep 20 '22 15:09

Tim Lehner