meteorelec
asked on
Delete * from table, -i want this to run one everyday
I want run
Delete * from table,
once a day everyday, and i want to no what is the best way of automating this?
Delete * from table,
once a day everyday, and i want to no what is the best way of automating this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if there are no relationships in this table, replace DELETE * with a "TRUNCATE TABLE tableName " and create a job as Chap mentioned
Use SQL Server Agent.
Start SQL Server Management Studio (or Query Analyser - It's pretty much the same, so far as I remember) and make sure you can see the Object Explorer (F8 if you can't) and Expand SQL Server Agent, which is at the bottom. Right click Jobs, choose New Job. Give it a name, then click Steps, click New..., name the step, and ensure the Type in the drop down is T-SQL, and the correct database is selected. Type your SQL in to the text box, and click OK.
Then select schedules, and create a new schedule, so it runs when you want.
That's it!
If you can't see SQL Server Agent in the Object Explorer, you may need to start the service ...
Also, if you want to empty a table each day, it's better to use TRUNCATE TABLE [tablename]
Hope that helps
Start SQL Server Management Studio (or Query Analyser - It's pretty much the same, so far as I remember) and make sure you can see the Object Explorer (F8 if you can't) and Expand SQL Server Agent, which is at the bottom. Right click Jobs, choose New Job. Give it a name, then click Steps, click New..., name the step, and ensure the Type in the drop down is T-SQL, and the correct database is selected. Type your SQL in to the text box, and click OK.
Then select schedules, and create a new schedule, so it runs when you want.
That's it!
If you can't see SQL Server Agent in the Object Explorer, you may need to start the service ...
Also, if you want to empty a table each day, it's better to use TRUNCATE TABLE [tablename]
Hope that helps