Export Microsoft SQL Server Tables and columns into an excel file

giveindia
giveindia used Ask the Experts™
on
I would like to export all the tables and column names of a said database to an excel file. What is the easiest way of going about this ?

Thanks,
Aditya
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Developer and Administrator
Commented:
USE <SaidDatabase>;

SELECT s.name + '.' + t.name AS table_name, c.name AS column_name
FROM sys.tables t
INNER JOIN sys.schemas s on t.schema_id = s.schema_id
INNER JOIN sys.columns c on t.object_id = c.object_id
ORDER BY table_name, column_name

Open in new window

Vitor MontalvãoIT Engineer
Distinguished Expert 2017

Commented:
Use the Import/Export wizard
ExportData.PNG
And when requesting the source query paste the following:
SELECT t.name AS TableName, c.name AS ColumnName
FROM sys.tables t
	INNER JOIN sys.columns c ON c.object_id = t.object_id
ORDER BY t.name, c.column_id

Open in new window

Author

Commented:
Thanks that worked great.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial