Open In App

How to Export a Table Data to a PDF File in SQL?

SQL Server is a versatile database. It is used across many industries. We can use AZURE data studio as well as SQL Server Management Studio for doing various operations (DDL, DML, Stored Procedure, Trigger preparations) etc., SQL  Server supports the portability of data using the EXPORT option. By default, both tools support exporting data to CSV, XSL, or flat-file format. This article let us see how to export table data to a PDF file.

Let us start that by creating a database, table and proceed



Step 1: First we create a database.

Query:



-- DATABASE CREATION
CREATE DATABASE GEEKSFORGEEKS
GO

Step 2: Now we create a table.

Query:

-- MAKE DATABASE ACTIVE
USE GEEKSFORGEEKS
--CREATE A TABLE
CREATE TABLE [dbo].[AuthorDetails] (
   [ID]         INT          NOT NULL,
   [AUTHORNAME] VARCHAR (20) NULL,
   [ADDRESS]    VARCHAR (20) NULL,
   [NOOFPOSTS]  INT          NULL,
   [SKILLSETS]  VARCHAR (100)  NULL
);

Step 3: After creating a table, we insert values into the table.

Query:

--INSERT DATA INTO THE TABLE
INSERT INTO AuthorDetails (ID,AUTHORNAME,ADDRESS,NOOFPOSTS,SKILLSETS)
VALUES (1,'GEEKA','CHENNAI',50,'JAVA,PYTHON,MONGODB');
INSERT INTO AuthorDetails (ID,AUTHORNAME,ADDRESS,NOOFPOSTS,SKILLSETS)
VALUES (2,'GEEKB','CHENNAI',50,'JAVA,MONGODB,SQL SERVER');
INSERT INTO AuthorDetails (ID,AUTHORNAME,ADDRESS,NOOFPOSTS,SKILLSETS)
VALUES (3,'GEEKC','CHENNAI',20,'PYTHON,MONGODB,ORACLE');
INSERT INTO AuthorDetails (ID,AUTHORNAME,ADDRESS,NOOFPOSTS,SKILLSETS)
VALUES (4,'GEEKD','CHENNAI',100,'JAVA,PYTHON,MONGODB,ORACLE,SQL SERVER');
INSERT INTO AuthorDetails (ID,AUTHORNAME,ADDRESS,NOOFPOSTS,SKILLSETS)
VALUES (5,'GEEKE','BANGALORE',50,'ANDROID,SWIFT,MONGODB');

Step 4: To see inserted values we use the following queries.

Query:

 -- SELECT THE DATA
SELECT * FROM AuthorDetails;

Output:

 

Step 5: By default, Azure data studio and SQL Server Management Studio supports for exporting of data to CSV, XLS and flat file. We can able to export the table data to PDF once this process is done. In SQL Server Management studio, we will get additional options as shown below:

 

 

 

 

 

Article Tags :
SQL