Open In App

How to Save Results With Headers in SQL Server Management Studio?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will be looking at how to save results with headers in SQL server management studio. We will be first creating a table to insert data into it, and then printing the contents of the table, then we see how to save results with headers in the Microsoft SQL server management studio.

Step 1: We will create a database

The following query is used to create a database.

Query:

CREATE DATABASE db_gfg;

Step 2: Specifying the usage

We use the following query to define which database we will use.

Query:

USE db_gfg;

Step 3: Table Creation

We will use the following query to create a 3-field table. 

Query:

CREATE TABLE gfg_table
(NAMES VARCHAR(100),
TITLES INT,
DOB DATE);

Step 4: Putting data inside the table

The following query is used to insert data into the table 

Query:

INSERT INTO gfg_table
VALUES
('PV Sindhu',10,'19950705'),
('Srikanth Kidambi',10,'19930207'),
('Lakshya Sen',3,'20010816');

Step 5: Print all the data of the table

We use the following query the print all the data of the table

Query:

SELECT * FROM gfg_table;

Output:

Step 6:

Click on Tools>Options. After that, the following dialog box appears. Then click on Query Results.

Step 7:

Then click on SQL Server>Results to Grid.

Step 8:

Then check the checkbox named “Include column headers when copying or saving the results”.

Step 9

Select a cell in the grid that appears after execution of Step 5, and press Ctrl+A.

Step 10

After that Right Click and choose “Save Results As”. Here we will be saving the results as a CSV file. Given below is the CSV file obtained:


Last Updated : 25 Jan, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads