I've never done this, so apologies if I'm being quite quite vague.
I need to run a long series of INSERT
SQL queries. This data is inserted in a table for being processed by a web service's client, ie the data is uploaded on a different server and the table gets cleared as the process progresses.
I have tried to add a delay to each Insert
statement like so
WAITFOR DELAY '00:30:00'
INSERT INTO TargetTable (TableName1, Id, Type) SELECT 'tablename1', ID1 , 1 FROM tablename1
WAITFOR DELAY '00:30:00'
INSERT INTO TargetTable (TableName2, Id, Type) SELECT 'tablename2', ID2 , 1 FROM tablename2
But this has the disadvantage of assuming that a query will finish executing in 30 minutes, which may not be the case.
I have run the queries manually in the past, but that's excruciatingly tedious. So I would like to write a program that does that for me. The program should:
Run each query in the order given
Wait to run the next query until the previous one has been processed, ie until the target table is clear .
I'm thinking of a script that I can copy into the command prompt console, SQL itself or whatever and run.
How do I go about this? Windows service application? Powershell function?
I would appreciate any pointers to get me started.
You need to schedule job in SQL Server
http://www.c-sharpcorner.com/UploadFile/raj1979/create-and-schedule-a-job-in-sql-server-2008/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.