How to Import Data from Script File into SQL Server

How to Import Data from Script file into MySQL Server? Detailed instructions on how to import data from SQL Server Management Studio (SSMS)

Hello everyone, in the previous articles, I have been with you to install SQL Server, create a connection to SQL Server through SSMS (SQL Server Management Studio) and learn about some basic operations with SQL Server. already.

In this next article, I will learn with you how to open and run a script file (file containing SQL statements) to create tables and Insert sample data into SQL Server through SQL Server. SSMS.

#first. Design of the database

Understanding and grasping the design of the database is a very important thing when you work with database management systems.

Below is the design of the sample database that I will use in this article. All has been written as Script. You can download the file here or here.

How to Import Data from Script File into SQL Server Picture 1How to Import Data from Script File into SQL Server Picture 1

#2. Create new database

First, you connect to the SQL Server database through SSMS as I have instructed in previous posts.

How to Import Data from Script File into SQL Server Picture 3How to Import Data from Script File into SQL Server Picture 3

Then create a new database by clicking Database => and selecting New Database… as shown below.

How to Import Data from Script File into SQL Server Picture 5How to Import Data from Script File into SQL Server Picture 5

Because in the Script I have defined the database name as BikeStores, so in the Database name section, you should set it to BikeStores to avoid Script compilation errors.

=> After naming, click OK to continue.

How to Import Data from Script File into SQL Server Picture 7How to Import Data from Script File into SQL Server Picture 7

Okay, so we already have a database called BikeStores. However, at this point our database is still empty and nothing.

How to Import Data from Script File into SQL Server Picture 9How to Import Data from Script File into SQL Server Picture 9

#3. Open and run Script files in SSML

Next we will open the Script and run it to add the tables and sample data to the newly created database.

Implementation: You go to File => select Open => and select File as shown below. Or you can use the key combination CTRL + O for fast.

How to Import Data from Script File into SQL Server Picture 11How to Import Data from Script File into SQL Server Picture 11

The first Script (Create Objects) will be the Script used to create the tables in the database. You will open and run this file first to create the tables in the database.

How to Import Data from Script File into SQL Server Picture 13How to Import Data from Script File into SQL Server Picture 13

After opening, click Execute to compile that Script.

How to Import Data from Script File into SQL Server Picture 15How to Import Data from Script File into SQL Server Picture 15

And now in the Tables section you will see that all the tables as shown in the design have been successfully created, in addition, there will be a message with the content Commands completed successfully in the Messages section.

How to Import Data from Script File into SQL Server Picture 17How to Import Data from Script File into SQL Server Picture 17

You do the same with the 3rd file (Load data) which will add sample data to the database tables.

How to Import Data from Script File into SQL Server Picture 19How to Import Data from Script File into SQL Server Picture 19

Continue to click Execute to compile the Script.

How to Import Data from Script File into SQL Server Picture 21How to Import Data from Script File into SQL Server Picture 21

You can observe in the Returned Messages section as shown below that the data has been successfully added.

How to Import Data from Script File into SQL Server Picture 23How to Import Data from Script File into SQL Server Picture 23

To check, you can open any table to see if the data has been added or not. Here I open the table production.categories

How to Import Data from Script File into SQL Server Picture 25How to Import Data from Script File into SQL Server Picture 25

#4. Epilogue

Okay, the process of importing data from into SQL Server Management Studio is also relatively simple, isn't it.

Through this article, I believe you already know how to use Script files to create tables as well as add data to the database in SQL Server, right!

In fact, when doing a project, one can export a Database (Export) into a Script file that can be carried to other machines to run very conveniently.

Okay, see you in the next articles about SQL Server.

4.3 ★ | 3 Vote