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.

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

#2. Create new database

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

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

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

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

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.

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

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

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

#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.

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

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.

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

After opening, click Execute to compile that Script.

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

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.

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

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

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

Continue to click Execute to compile the Script.

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

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

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

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

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

#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.

Update 13 July 2021
Category

System

Mac OS X

Hardware

Game

Tech info

Technology

Science

Life

Application

Electric

Program

Mobile