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