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.
You should read it
- How to Import PST Files to Office 365
- How to Import Models Into Blender on PC or Mac
- Instructions for importing JSON into Google Sheets
- How to create and run a PowerShell script file on Windows 10
- How to import data from photos into Excel
- How to convert PowerShell script file (.ps1) to .exe by IExpress on Windows 10
- Secedit: import command in Windows
- How to copy styles between 2 Word files (Import, import styles from the old word file to the new file)
- How to Import Contacts from Excel File to Android Phone
- Upload File in PHP
- Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 5
- The best SFTP server and tools for secure file transfer
May be interested
How Does Virtualization Work with SQL Server & What Are The Benefits?
Basic operations with Database in Microsoft SQL Server
Steps to install Microsoft SQL Server on Windows 10
How to make a connection to SQL Server through SSMS
Instructions on how to connect to MySQL Server in IntelliJ
What's new in SQL Server Management Studio 18.7?