• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

Export Microsoft SQL Server Tables and columns into an excel file

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
0
giveindia
Asked:
giveindia
1 Solution
 
Máté FarkasDatabase Developer and AdministratorCommented:
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

0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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

0
 
giveindiaAuthor Commented:
Thanks that worked great.
0

Featured Post

Managing Security & Risk at the Speed of Business

Gartner Research VP, Neil McDonald & AlgoSec CTO, Prof. Avishai Wool, discuss the business-driven approach to automated security policy management, its benefits and how to align security policy management with business processes to address today's security challenges.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now