SQL Server 2008 Schedule Timed Job to Run - sql-server-2008

I have a .sql script file that I want to run once every 24 hours. What are the best (and easiest) steps to produce a scheduled task in SQL Server 2008 to do this?
Thanks.

You could use the SQL Server Agent (if you are not using the Express version of SQL Server). In Management Studio, expand the SQL Server Agent node, right-click on Jobs and click New Job...
From there you will be able to schedule all kinds of jobs, including running a script every 24 hours.

You can create a job with the SQL Server Agent.
SQL Server Agent uses SQL Server to store job information. Jobs
contain one or more job steps. Each step contains its own task, for
example, backing up a database.
SQL Server Agent can run a job on a schedule, in response to a
specific event, or on demand. For example, if you want to back up all
the company servers every weekday after hours, you can automate this
task. Schedule the backup to run after 22:00 Monday through Friday; if
the backup encounters a problem, SQL Server Agent can record the event
and notify you.
You can run a job based on a specific schedule and it can execute a stored procedure, SSIS, etc.
To create a new job, in SQL Server Management Studio, under the SQL Server Agent, right-click the Jobs and select New Job.
Here is a step by step from MSDN on creating a job:
http://msdn.microsoft.com/en-us/library/ms190268.aspx

In you SQL Server Agent
1. right click jobs to add a new job
2. Give it a name and make sure the owner has the access the execute access to the database.
3. under steps and a new step. You can simply copy paste the script in the text area, select the database you want to run in on click OK.
4. under schedule click add new schedule and select time, occurrence, start and end time
5. click ok and you are done.
Hope it helps you and anyone else who came across this and still wasn't sure how it works just like me :)

Well, if you do not have SQL agent or full SQL version: you could schedule a task to run a batch file in Windows scheduler that "calls" on the SQL script. This is my batch file for example: SQLCMD.EXE -S sqlServerInstanceName -E -i C:_software\mySQLscript2Execute.sql . Remember to save your file with .bat extension. Thanks : chagbert

Related

How to schedule a job in mysql workbench

In MySql DB, How to populate a specific table with the data of an excel file every day.
I want this job to run every morning at 8.00am.
How can i do this?
You cannot do that with MySQL Workbench. You need some external timer service (cron job in linux/mac, scheduler service in Win) to run a batch file to make the import.

Create a task in SQL or Windows Server to clean a directory nightly

I have a temp directory on my website where users export data in .csv files.
The newer intranet apps delete the file after it's sent to the client but the legacy apps just leave the files in this directory.
I'd like to create a task to clean this directory nightly. There can be .csv files and directories with files in them.
Basically I want to run:
del *.* /s
rd /s
...every night at midnight.
Would love to do it with a SQL maintenance task but that only runs on the actual SQL server and doesn't work with mapped drives (unless I'm missing something).
How does one go about performing this task?
Can it be done through SQL server somehow?
You have the option of creating "Jobs" that run stored procedures or bits of code. These jobs can be scheduled to run daily, weekly, etc. Check out this thread: How can i create SQL Agent job in SQL Server 2008 standard?
Sounds like you may be using SQL Server Express Edition for which Microsoft removed the SQL Agent on 2008 and above. In cases like this you're best choice is using the Windows Scheduler to run your commands via a batch file.

Copy MSSQL data to MySQL DB every 5 mins?

I'm looking for some advice over the best way to transfer data from a local MSSQL DB to a remote MYSQL database every 5 mins?
At the moment I am using a tool called SQLYOG which allows me to create a connection to my local MSSQL database and to my remote MYSQL server and set up some queries and mapping.
It also allows me to create a windows scheduled task which runs every 5 minutes.
This solution has been working ok but is only about 95% reliable and seems to struggle sometimes.
This software runs in GUI mode and via cmd prompt so is reasonably light weight when running a scheduled task.
Does anyone know of any other light weight tools or methods I can use to get the same outcome?
You can use SymmetricDS. its a good & efficient open source tool for this purpose.
you can use SSIS packages to do that.
SQL Server Integration Services (SSIS) is a component of the Microsoft SQL Server database software that can be used to perform a broad range of data migration tasks.
Couple of options:
1. create linked server to mysql then copy rows via linked server in sp, set sql job to execute.
2. build ssis package and run it in sql job.
What I feel is the best soultion for this is to design an ETL job using either SSIS or Talen Open Studio.

Getting SQL agent in mysql

I am coming from a SQL server 2008 background. I have a mysql local server running, and I wanted to set up some scheduled jobs via the sql agent. I have found some sketchy third party sql agents for mysql but none built in. Is there a sql agent or a recommended one for mysql? Thank you.
Usual approach is to set up a cron job to run a script. I used to use Perl for the scripts, but bash etc will do it as well.

Job On Sql Server Agent does not complete, but it does in BIDS?

My package works like a treat in SSIS ( BIDS ) and executes in 4 minutes . Logging onto integrations services in SQL Server management studio and importing it into file system or stored packages and then running it, again takes 6 minutes .
Now moving it to SQL Server Agent . It runs and runs .... Looks like when it comes to a few tasks that mean running a bat file to open an excel file then a vbs file to run a few macros it seems it cannot cope with it . I worked this out using sql server profiler . Killed the job after 40 mins and no meaningful errors . Even looked at the Windows NT logs !
I need to get this package working on sql server agent so it is automated and I can schedule it to run a few times every day .
Can anyone help me resolve this as I am stuck ?
SQL Server User / Credentials / proxy Account has been set up correctly and earlier in the control flow it does run another bat file which copies across a file to another directory .
This is because SQL Server Agent does not load a user's environment to be able to run Excel macros. You need to schedule Excel macros via the Windows Scheduler (and log in at least once to clear the Excel licensing little pop-ups that come up).