From:       To:      

Import T-SQL script file

This article explains how to import T-SQL script file to Microsoft SQL server using the most popular tools.

1. SQL Server console client (sqlcmd.exe)

Syntax of the command line depends on the structure of T-SQL script. If the script contains 'CREATE DATABASE' statement you should call the tool as follows:

sqlcmd.exe -S {SQL Server} -U {user name} -P {password} -i {T-SQL script file name}

Otherwise:

sqlcmd.exe -S {SQL Server} -U {user name} -P {password} -d {database name} -i {T-SQL script file name}

Of course you need to replace parameters in figure brackets {...} by actual values. You can omit 'user name' and 'password' parameters to connect to Microsoft SQL server using Windows authentication.

2. SQL Server Management Studio

To import T-SQL script file into Microsoft SQL server using this tool, take the following steps:

  1. connect to the destination SQL Server
  2. select 'Open' menu item and specify T-SQL script file
  3. click 'Execute' toolbar button

Note, that if your T-SQL script file is large (100+ MB), it is better to import it using sqlcmd.exe because SSMS may crash on it.

Have questions? Contact us