How to export data to .csv file

By FoxLearn 7/26/2024 2:02:17 AM   3.32K
Export data to .csv file from SQL Server using the bcp (Bulk Copy Program) utility or SQL Server Management Studio (SSMS).

How to export data to .csv file in sql server

Open SQL Server Management Studio and connect to your database, then select Object Explorer on the left.

Next, select your database you want to export data, then right-click and select Tasks => Export Data...

sql import export

Click Next button

sql server export csv

Connect to your database, then click Next button.

sql export data to csv

Enter csv file name, then click Next button.

sql server export csv data

Select copy data from one or more tables or views, then click Next button.

export data to csv file

Select source table or view you want to export data to csv file. You can also click Preview button to see your data before exporting.

sql preview data

Click OK button, then click Next button.

export data to csv file

Click Next button.

export data to csv file

Click Finish button.

export data to csv file

Click Close button to finish.

You can also use the bcp (Bulk Copy Program) utility to export data to a CSV file in SQL Server.

Open Command Prompt or PowerShell with administrative privileges, then use the following syntax to run the bcp command

bcp "SELECT * FROM YourTableName" queryout "C:\YourFolder\YourFile.csv" -S YourServerName -d YourDatabaseName -c -t , -T

- Replace YourTableName with the name of the table you want to export.

- Replace YourServerName with the name of your SQL Server instance.

- Replace YourDatabaseName with the name of your database.

- Replace C:\YourFolder\YourFile.csv with the path where you want to save the CSV file.

Press Enter to execute the command. You may be prompted to enter your SQL Server authentication details if -T option is not used. If you want to use SQL authentication, you can replace -T with -U YourUsername -P YourPassword.

By following these steps, you can export data from SQL Server to a CSV file using either the bcp utility or SQL Server Management Studio.

VIDEO TUTORIAL