SQL: Using SQLCMD for Large SQL Scripts

When using SQL Server Management Studio, executing very large queries can bring up a message that the operation cannot be completed, and that there is not enough storage to process the command. An example of a large file would be a sql script that inserts thousands of records into a table.

Rather than using the GUI, we can use Sqlcmd at the command line. Open a CMD Prompt as Administrator. There is no need to change to any specific directory in the CMD prompt. Enter the following, and press Enter:

C:\>sqlcmd -S ServerName -d DataBaseName -i "FolderPath\FileName.sql"

Run a SQL script from the command prompt

-S indicates the name of the SQL Server instance
-d indicates the name of the SQL database
-i indicates the file path to the .sql input file

For more information on available paramteters, enter:

C:\>sqlcmd /?

Enter sqlcmd /? for more information

Comments

Popular posts from this blog

VBScript: Ensure Backslash Folder Path

AutoStore: Create a Custom RRT

AutoStore: Workflow Loop Example