John Molina
John Molina

Reputation: 321

Running a script multiple times

I need to run an SQL script as a job and I would like it to run twice when scheduled. How can I do that on the script below.

IF EXISTS (SELECT name FROM sysindexes
           WHERE name = 'IgnoreList_Specification')
           DROP INDEX IgnoreList.IgnoreList_Specification
GO
CREATE INDEX IgnoreList_Specification ON IgnoreList
       (Specification)
       WITH  FILLFACTOR = 90 ON [PRIMARY]
GO
IF EXISTS (SELECT name FROM sysindexes
           WHERE name = 'IgnoreList_Custom')
           DROP INDEX IgnoreList.IgnoreList_Custom
GO
CREATE INDEX IgnoreList_Custom ON IgnoreList
       (Custom)
       WITH  FILLFACTOR = 90 ON [PRIMARY]
GO
IF EXISTS (SELECT name FROM sysindexes
           WHERE name = 'IgnoreList_Custom1')
           DROP INDEX IgnoreList.IgnoreList_Custom1
GO
CREATE INDEX IgnoreList_Custom1 ON IgnoreList
       (Custom1)
       WITH  FILLFACTOR = 90 ON [PRIMARY]
GO

Upvotes: 1

Views: 1697

Answers (1)

S3S
S3S

Reputation: 25122

For each batch you want to run twice, use GO 2. This will execute the batch twice

https://msdn.microsoft.com/en-us/library/ms188037.aspx

If you want to run the entire job twice, you can schedule one to run after the other finishes, or just duplicate the steps.

Upvotes: 1

Related Questions