Press "Enter" to skip to content

Import SQL file to SQL Server [Simple and Fast]

sunitha udai 0

Still struggling in importing .SQL file..?? Then how to import sql file? Here is a simple solution for you..

To import the .sql file in the SQL Server Management Studio: Open SQL Management Studio, go to File, Open and select the SQL file. It will open your file in a query window. Create a database_name.

Now here is the trick that we’re going to use to import .sql file in very simple step

use database_name
go

Insert this two lines first in query window. Do Refresh the database.
Its done.. Quiet easy know. 🙂

In-depth description for the above explanation:

Here for example, I took “Meeting_Management.sql” file. Now I’m going to import this file in simple way.
First Create Database, with the same name of .sql file you have. Here I’m going to create a database with the same name in sql server “Meeting_Management”
Next Databases > Right Click > New Database : Enter the database name “Meeting_Management”
Click Add
(Now open our sql file “Meeting_Management.sql” in SQL server)
Select File > Right Click on File > Open with > Select SQL server

Now here is the trick that we’re going to use to import .sql file in very simple step
use Meeting_Management
go

Note: Here, my file name is Meeting_Management. Else you need write your file name
insert this two lines first

Now in Menubar > Select Query > Select Execute (Or Just Click F5 to execute Query)
Do Refresh the database.
Its done..

 

Import .sql file using one of these Professional methods.

Method 1: SQL Server Import and Export Wizard Using Start Menu:

  • Start menu > All apps > Microsoft SQL Server 2016 > SQL Server 2016 Import and Export Data
  • Welcome to SQL Server Import and Export Wizard > Next
  • Choose a data source and settings related to that > The data provider is typically a name of the data source – for example, SQL Server, Oracle, flat files, Excel, or Access > Next
  • Choose a Destination > Data Source: Choose SQL Server Native Client 11.0 from the drop-down menu > Server Name: It’ll automatically shown in dropdown > Select server name > Authentication: Normally use Windows Authentication > Database : Choose the database > Next
  • Select Table Copy or Query page > Select Copy data from one or more tables or views >

Selected Source Tables and Views dialog allows you to select the tables and views that you want to import

Tips:

Preview: You can click the Preview button to view the first 100 rows of the data in the data source

Edit Mappings: You can click the Edit Mappings button to review the column mappings from the data source. You have an option of Edit SQL button to review and/or edit the SQL in the destination data source. Click ok until you get an option Save and Execute Package dialog.

Save Package and Run > Complete Wizard: Finish

Method 2: Import .SQL file using Command Prompt

  • Go to: Start-> Run -> Type cmd and press enter
  • Once the command line is on screen tell SQLCMD to import your database by doing something like this:

sqlcmd -S [server instance name] -d [database name] -i [filename you want to import]

Note: If you’re not sure about the server instance name. Open SQL Server Management Studio > Login > Server Name (Server name itself is an instance name)

Method 3: SQL Server Import and Export Wizard Using SSMS (SQL Server Management Studio)

  • Open SQL Server Management Studio > Expand Databases > Right-click on database > Tasks > Import Data
  • Welcome to SQL Server Import and Export Wizard > Next
  • Choose a data source and settings related to that > The data provider is typically a name of the data source – for example, SQL Server, Oracle, flat files, Excel, or Access > Next
  • Choose a Destination > Data Source: Choose SQL Server Native Client 11.0 from the drop-down menu > Server Name: It’ll automatically shown in dropdown > Select server name > Authentication: Normally use Windows Authentication > Database : Choose the database > Next
  • Select Table Copy or Query page > Select Copy data from one or more tables or views >

Selected Source Tables and Views dialog allows you to select the tables and views that you want to import

Tips:

Preview: You can click the Preview button to view the first 100 rows of the data in the data source

Edit Mappings: You can click the Edit Mappings button to review the column mappings from the data source. You have an option of Edit SQL button to review and/or edit the SQL in the destination data source. Click ok until you get an option Save and Execute Package dialog.

Save Package and Run > Complete Wizard: Finish

Method 4: SQL Server Import and Export Wizard Using SSDT (SQL Server Data Tools)

Why SSDT? If you don’t have Microsoft SQL Server installed on your computer, then you can install SQL Server Data Tools (SSDT) to run SQL Server Import and Export Wizard.

https://docs.microsoft.com/en-us/sql/ssdt/download-sql-server-data-tools-ssdt

  • On the Project menu, click SSIS Import and Export Wizard (Or) In Solution Explorer, right-click the SSIS Packages folder, and then click SSIS Import and Export Wizard.
  • Welcome to SQL Server Import and Export Wizard > Next
  • Choose a data source and settings related to that > The data provider is typically a name of the data source – for example, SQL Server, Oracle, flat files, Excel, or Access > Next
  • Choose a Destination > Data Source: Choose SQL Server Native Client 11.0 from the drop-down menu > Server Name: It’ll automatically shown in dropdown > Select server name > Authentication: Normally use Windows Authentication > Database : Choose the database > Next
  • Select Table Copy or Query page > Select Copy data from one or more tables or views >

Selected Source Tables and Views dialog allows you to select the tables and views that you want to import

Tips:

Preview: You can click the Preview button to view the first 100 rows of the data in the data source

Edit Mappings: You can click the Edit Mappings button to review the column mappings from the data source. You have an option of Edit SQL button to review and/or edit the SQL in the destination data source. Click ok until you get an option Save and Execute Package dialog.

Save Package and Run > Complete Wizard: Finish

 

Thank you for reading Brainybay article. We hope you enjoy. Still have Questions? or Any Suggestions..!! You can discuss with us. We’re happy to hear something from you.

Leave a Reply

Your email address will not be published. Required fields are marked *