How to Import Data from Script File into SQL Server

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 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 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 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 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 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 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 13

After opening, click Execute to compile that Script.

How 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 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 19

Continue to click Execute to compile the Script.

How 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 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 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

May be interested

  • Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 5Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 5
    part i and part ii of this series showed you how to install powershell and simple smo and wmi cmdlets. in part iii, i showed you how to script powershell and connect to sql server. in part iv, i will show you how to use the powershell script to loop through the contents of the file and connect it
  • The best SFTP server and tools for secure file transferThe best SFTP server and tools for secure file transfer
    sftp prevents the transfer of unencrypted and simultaneous login information, it also creates a unique identifier, which must be retransmitted from the client to complete the data transfer.
  • Tricks to import data in Excel fastestTricks to import data in Excel fastest
    frequently use excel to enter data, calculate and process data. if you enter data faster, the time spent on calculating and processing data will be more. there are many faster ways to import excel data that you can use.
  • Instructions for setting up individual FTP Server with FileZillaInstructions for setting up individual FTP Server with FileZilla
    unlike http - designed to forward hyper - text data over tcp connections, standard ftp ensures that the server responds to requests as soon as it receives a signal from the host. not only provides fast and accurate file transfer, but also security, gives users more options in the process of downloading and uploading data ...
  • How to import Excel data into Python scripts with PandasHow to import Excel data into Python scripts with Pandas
    instead of manually copying data into a database, here is a quick guide on how to load excel data into python using pandas.
  • Automatically backup web server data with WinSCP via FTPAutomatically backup web server data with WinSCP via FTP
    for website system administrators, data backup and recovery must always be the top priority. and in fact, there are many ways to do this that are applied daily. in the following article, we will show you how to do this with the free winscp tool and a little knowledge.
  • How to import passwords from CSV file into Google ChromeHow to import passwords from CSV file into Google Chrome
    if you already have passwords in a csv file and want to import them into chrome, you can easily do this in the google chrome browser.
  • How to import and export OVA files in VirtualboxHow to import and export OVA files in Virtualbox
    virtualbox has a graphical application that you can use to create and manage your virtual machines easily on a desktop or workstation.
  • Data types in SQL ServerData types in SQL Server
    below are the data types (data types) in sql server, including character strings, numbers and times / dates.
  • Query XML data from a table with XML data typeQuery XML data from a table with XML data type
    this article illustrates how to create an xml schema, create a table with an xml data type, import an xml file into a table with an xml data type, query the xml file, and produce the same result as the actual result set. shown by sql transact commands.