Sunday, March 31, 2013

Sql Server 2008,2012: Run Sql Script File From Command Line

To Start Sql Command reform following link:
http://msdn.microsoft.com/en-us/library/ms166559(v=sql.105).aspx

Run the following command in the command prompt.

Replace "C:\myScript.sql" with the location of your sql code file location.

[code language="sql"] sqlcmd -S myServer\instanceName -i C:\myScript.sql[/code]

The above command will return the result set in command prompt.

If you prefer the result in a text file use the code below:

[code language="sql"] sqlcmd -S myServer\instanceName -i C:\myScript.sql -o C:\EmpAdds.txt[/code]

Happy Coding :)

No comments: