Friday, March 9, 2012

Schedule SQL script

I been trying to figure out how to do this for a while but finally given in and decided to ask here.
I am using SQL express and I think that desnt support automation of SQL scripts (please correct me if I am wrong!)

I want to run a backup script and the plan was to use a bat file and windows task scheduler. But for the life of me I cannot get the bat file to work after trying loads of different example from my searches.

Any help is apreciatedI think you are correct that express doesn't include Agent, which is the scheduling component that comes with the higher SKUs of sql server.

what does the bat file look like? are you using sqlcmd.exe? that's what I would recommend.|||hmm does it have to be called sqlcmd.exe?
I had a file called script.bat and i was writing a one line command to execute the SQL script. I really dont have any idea what im doing I was just following what some forums were saying when I searched :S

thanks|||sqlcmd.exe is a console app you can use to execute sql scripts from the cmd line. the equivalent in 2000 is osql.exe.|||I'm guessing here but I would say that you can pass parameters to sqlcmd.exe can you not? So you could call sqlcmd.exe <parameter1> <parameter2> ... from your batch file and it should run your backup commands for you.

How to connect using SQLcmd (http://msdn2.microsoft.com/en-us/library/ms188247.aspx)
How to execute commands from SQLcmd (http://msdn2.microsoft.com/en-us/library/ms253126(VS.80).aspx)
A break down of SQLcmd options (http://http://www.yukonxml.com/Reference/default.aspx?t=SQLCMD) <-- CHECK THIS ONE OUT.

Bear in mind that your batch script needs to know where the sqlcmd is run from. So it either needs to be in your PATH setting or you need to run your batch script from the same directory (not advisable).|||I really dont have any idea what im doing
You might want to take a step back and make yourself familiar with the SQL Server environment and all the tools that come with it before trying to actually implement something.
Sometimes it's quicker to read the manual first and only then start "coding", instead of trying to cleanup the mess you made because you "don't have any idea what you are doing".

No comments:

Post a Comment