There are instances where we might need to run some default scripts on a specified server once SQLCMD gets connected. It can be achieved in just three steps as explained below:
Step 1: Create a script file which you wanted to fire when SQLCMD gets connected to your SQL Server.
For keeping the example simple, I used the following line and saved it as SqlCmdStartUpScripts.sql
print 'Welcome today''s date is: ' + (convert(varchar, getdate()))
Step 2: Open DOS prompt and type set sqlcmdini=c:\vadivel\sql related\scripts\SqlCmdStartUpScripts.sql
Step 3: Then type SQLCMD and press Enter.
Refer the below screenshot for the sample output.
Step 1: Create a script file which you wanted to fire when SQLCMD gets connected to your SQL Server.
For keeping the example simple, I used the following line and saved it as SqlCmdStartUpScripts.sql
print 'Welcome today''s date is: ' + (convert(varchar, getdate()))
Step 2: Open DOS prompt and type set sqlcmdini=c:\vadivel\sql related\scripts\SqlCmdStartUpScripts.sql
Step 3: Then type SQLCMD and press Enter.
Refer the below screenshot for the sample output.
Comments
If there are certain scripts which you wanted to run on a daily basis or as a routine job you can put those as your startup script!
Moreover I have just spoken about a feature available in SQL 2005 it all depends on our individual creativity / knowledge / need to use it at right place.