Saturday, June 26, 2010

SQLCMD - Examples

sqlcmd Switches
-S >> ServerName
-D >> DatabaseName
-U >> UserName
-P >> Password
-Q >> Query
-o >> OuputFile

sqlcmd -SSQL2005_FIRST -Ucalyan -Pcalyan
-dDatabaseA -Q"select * from sampledata"

sqlcmd -SSQL2005_FIRST -Ucalyan -Pcalyan
-dDatabaseA -Q"select * from sampledata" -o"c:\sampledata.txt"


sqlcmd -SSQL2005_FIRST -Ucalyan -Pcalyan
-dDatabaseA -Q"EXEC MYPROC1"

sqlcmd -SHOME-CB\SQL2005_FIRST -Ucalyan -Pcalyan
-dDatabaseA -Q"exec msdb.dbo.sp_start_job @job_name = 'TestJob'"

No comments: