Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Export Data From SQL to CSV

by suresh

When there is a discussion about exporting data from SQL Server to CSV file, we immediately look for the SQL Server Integration Services. But, you can achieve the same result from the SQL Server Management Studio with ease. In this article, we will show you multiple approaches to export data from SQL to CSV with a practical example.

For the first Export Data From SQL to CSV example, we are going to use the below-shown data.

Export Data From SQL to CSV 1

Export Data From SQL to CSV – Approach 1

In this example, we are going to export Employees table data present in the SQL tutorial database to CSV file (that we will create) in the local hard drive. For this, please select all the columns, either clicking the top left corner or selecting Select All option from the context menu.

Export Data From SQL to CSV 2

After selecting all the columns, please go to the top left corner, and right-clicking there will open the context menu. Please select the Save Result As.. from it.

Export Data From SQL to CSV 3

That will open a Save Dialog Box to save the file in your local hard drive. From the below screenshot you can see that, we are saving the file in D drive

Export Data From SQL to CSV 4

Let’s navigate to the file system address that we provided and check for the file name EmployeeData.

Export Data From SQL to CSV 5

Double click on csv file to check the result

Export Data From SQL to CSV 6

Export Data From SQL to CSV Approach 2

Within the Object Explorer, right-click on the database will open the context menu. Please select the Tasks and then Export Data.. option from it to Export Data From SQL to CSV.

Export Data From SQL to CSV 7

Once you select the Export Data.., It will open SQL Server Import and Export Data Wizard. The first page is welcome page, and you can avoid this page by clicking the Do not show this Starting page again option

Export Data From SQL to CSV 8

Choose a Data Source Page: This window is used to configure the source from which the data is coming. Our source is the SQL Server database, so we selected the SQL Server Native Client as Data Source.

Export Data From SQL to CSV 9

Next, we are using the Windows authentication to log in to the PRASAD server instance. Please use SQL Server Authentication in real-time.

Export Data From SQL to CSV 10

Choose a Destination: This window is used to configure the destination (to where we want to copy this data).

Export Data From SQL to CSV 11

Our target is to save the data into a CSV file. So we are selecting Flat File Destination as our Destination

Export Data From SQL to CSV 12

Please click on the Browse button to choose the CSV file from our local drive

Export Data From SQL to CSV 13

We are creating new CSV in our D drive

Export Data From SQL to CSV 14

Click on the Open button to create a new CSV file.

Export Data From SQL to CSV 15

Next, select the Format that you want to assign.

Export Data From SQL to CSV 16

Specify Table Copy or Query: Here we have two options to Export Data From SQL to CSV

  1. Copy data from one or more tables or views: This option is to select from existing tables or view (All the columns data)
  2. Write a query to specify file data to transfer options: In real-time, we are going to use this option. Because there will be unnecessary columns in every table. So it is better to avoid them or selecting data with the condition.
Export Data From SQL to CSV 17

This window is used to select the source table from the SQL database. Here we are selecting the Employees table.

Export Data From SQL to CSV 18

You can change the Row and Column delimiters as per your requirements. If you are using a text file as the destination, then you can do many customizations. Click on the preview button to check the incoming data flow

Export Data From SQL to CSV 19

Save and Run Package: This page gives us the option to save the package in either SQL server or File system. For the time being, I am selecting the Run option immediately

Export Data From SQL to CSV 20

Click finish button to complete the Export Data From SQL to CSV Wizard

Export Data From SQL to CSV 21

From the below screenshot, you can observe the status: Success and Message.

Export Data From SQL to CSV 22

Placed Under: SQL

  • Install SQL Server
  • Install SQL Management Studio
  • Uninstall Management Studio
  • Install AdventureWorks Database
  • SQL Management Studio Intro
  • Connect SQL with sqlcmd utility
  • SQL Attach Database
  • SQL Detach Database
  • SQL Restore Database
  • Restore Database using BAK
  • SQL Rename Database with Files
  • Get SQL Database Names
  • SQL Create Table
  • SQL Rename Table
  • SQL Alter Table
  • SQL Add Column
  • SQL Rename Column
  • Get SQL Table Names in a DB
  • Find SQL Table Dependencies
  • Rename SQL Table & Column
  • SQL Global & Local Temp Table
  • SQL Table Variable
  • SQL Derived Table
  • SQL DATALENGTH
  • SQL Data Types
  • DML, DDL, DCL & TCL Cmds
  • SQL Query Builder
  • SQL ALIAS
  • SQL SELECT Statement
  • SQL SELECT DISTINCT
  • SQL SELECT INTO Statement
  • SQL INSERT Statement
  • SQL INSERT INTO SELECT
  • SQL BULK INSERT or BCP
  • SQL UPDATE Statement
  • SQL UPDATE from SELECT
  • SQL DELETE Statement
  • SQL TRUNCATE Table
  • SQL CASE Statement
  • SQL MERGE Statement
  • SQL Subquery
  • SQL CTE
  • SQL PIVOT
  • SQL UNPIVOT
  • SQL Clauses Examples
  • SQL TOP Clause
  • SQL WHERE Clause
  • SQL ORDER BY Clause
  • SQL GROUP BY Clause
  • SQL HAVING Clause
  • SQL Primary Key
  • SQL Foreign Key
  • SQL Referential Integrity
  • SQL Check Constraint
  • SQL Unique Constraint
  • SQL Default Constraint
  • SQL Clustered Index
  • SQL Non Clustered Index
  • SQL Filtered Indexes
  • SQL COALESCE Function
  • SQL IS NOT NULL
  • SQL IS NULL Function
  • SQL ISNULL
  • SQL JOINS
  • SQL CROSS JOIN
  • SQL FULL JOIN
  • SQL SELF JOIN
  • SQL Outer Joins
  • SQL Cross Join Vs Inner Join
  • SQL LEFT JOIN
  • SQL RIGHT JOIN
  • SQL AND & OR Operators
  • SQL Arithmetic Operators
  • SQL BETWEEN Operator
  • SQL Comparison Operators
  • SQL LIKE
  • SQL EXCEPT
  • SQL EXISTS Operator
  • SQL NOT EXISTS Operator
  • SQL INTERSECT
  • SQL IN Operator
  • SQL NOT IN Operator
  • SQL UNION
  • SQL UNION ALL
  • SQL IF ELSE
  • SQL ELSE IF
  • SQL WHILE LOOP
  • SQL Nested While Loop
  • SQL BREAK Statement
  • SQL CONTINUE Statement
  • SQL GOTO Statement
  • SQL IIF Function
  • SQL CHOOSE Function
  • SQL Change Data Capture
  • SQL Table Partitioning
  • SQL Table Partition using SSMS
  • SQL TRY CATCH
  • SQL VIEWS
  • SQL User Defined Functions
  • SQL Alter User Defined Functions
  • SQL Stored Procedure Intro
  • Useful System Stored Procedures
  • SQL SELECT Stored Procedure
  • SQL INSERT Stored Procedure
  • SQL UPDATE Stored Procedure
  • Stored Procedure Return Values
  • Stored Procedure Output Params
  • Stored Procedure Input Params
  • Insert SP result into Temp Table
  • SQL Triggers Introduction
  • SQL AFTER INSERT Triggers
  • SQL AFTER UPDATE Triggers
  • SQL AFTER DELETE Triggers
  • SQL INSTEAD OF INSERT
  • SQL INSTEAD OF UPDATE
  • SQL INSTEAD OF DELETE
  • SQL STATIC CURSOR
  • SQL DYNAMIC CURSOR
  • SQL FORWARD_ONLY Cursor
  • SQL FAST_FORWARD CURSOR
  • SQL KEYSET CURSOR
  • SQL TRANSACTIONS
  • SQL Nested Transactions
  • SQL ACID Properties
  • Create SQL Windows Login
  • Create SQL Server Login
  • SQL Server Login Error
  • Create SQL Server Roles
  • SQL Maintenance Plan
  • Backup SQL Database
  • SQL Ranking Functions Intro
  • SQL RANK Function
  • SQL PERCENT_RANK Function
  • SQL DENSE_RANK Function
  • SQL NTILE Function
  • SQL ROW_NUMBER
  • SQL Aggregate Functions
  • SQL Date Functions
  • SQL Mathematical Functions
  • SQL String Functions
  • SQL CAST Function
  • SQL TRY CAST
  • SQL CONVERT
  • SQL TRY CONVERT
  • SQL PARSE Function
  • SQL TRY_PARSE Function
  • SQL Calculate Running Total
  • SQL Find Nth Highest Salary
  • SQL Reverse String
  • SQL FOR XML PATH
  • SQL FOR XML AUTO
  • SQL FOR XML RAW
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy