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:
- First, click on Data Pump and then select the Export Data option
- After that select PDF Export format from the window.
- In this step select a server connection, a database and its schema, table(s), and view(s) that you want to export, and click Next.
- On the Output settings page, you have two main options:
- Export data into separate files, where you specify the path to the folder in which they will be saved.
- Export data into a single file, where you specify the path and the file name. We will find the list of files to be exported in the Exported files preview box.
- Now we can able to get the pdf data.