-2

I have a set of queries(more than 200)(in a notepad file) that i run every week in a sequence one by one. Can someone suggest what can i do to run them with one command. SSIS packages? Sql procedure?

I am a beginner. I am using SQL Server 2005

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Verma
  • 1
  • 2

2 Answers2

2

Have a look at the following: How do you import a large MS SQL .sql file?

For example:

sqlcmd -S <server> -i C:\<your file here>.sql -o
Community
  • 1
  • 1
Menelaos
  • 23,508
  • 18
  • 90
  • 155
1

If the queries are the same week in and week out, put them in a stored procedure, and schedule them with a SQL Server Agent job.

CREATE PROCEDURE dbo.WeeklyQueries
AS
BEGIN
  SET NOCOUNT ON;

  -- 200+ queries go here
END
GO

If you're feeling ambitious, separate them by function and turn them into several stored procedures.

Once you have the procedure(s), create a job with a Transact-SQL step that points to the procedure(s) in the right database(s), and either schedule it to run weekly or just run it on demand every week.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490