Automate execution of multiple SQL Server 2012 scripts in specific order - sql-server

I needed some guidance with a task I have never worked with SQL Server 2012. Your help would be very much appreciated. I have inherited a data model in SQL Server.
Basically, I have 5 SQL scripts:
Script A
Script B
Script C
Script D
Script E
For running successfully script B,it needs access to tables generated by script A to perform calculation. Basically, the scripts are feeding each other. I need to run the scripts in a specific order.
My first idea was "stored procedure". So far, I have in the past only written a stored procedure to execute code from the same script that do not require executing other scripts.
My question is, what are some ideas you propose for automatically executing the above 5 scripts in a specific order? how can I do this? What would you recommend me to think when doing this?
Running the complete list of scripts takes around 10 hours.

You could easily create a new SQL Server Agent Job task like this:
Expand the SQL Server Agent node and right click the Jobs node in
SQL Server Agent and select 'New Job'
In the 'New Job' window enter the name of the job and a description
on the 'General' tab.
Select 'Steps' on the left hand side of the window and click 'New'
at the bottom.
In the 'Steps' window enter a step name and select the database you
want the query to run against.
Paste in the T-SQL command you want to run into the Command window
and click 'OK'.
Click on the 'Schedule' menu on the left of the New Job window and
enter the schedule information (e.g. daily and a time).
Click 'OK' - and that should be it.
Repeat these steps for each scripts in the order you want them to run. And, there you go!

Related

How do you re-run an already executed query from 'Query History' pgadmin?

As in pgAdmin 4 screenshot, one can see a list of recently executed queries.
The play button, Execute / Refresh(F5) tool executes the most recent query instead of the selected/highlighted one.
I know I can click on a query, and from the right side pane click on copy and go to the Query Editor to run it.
My question is, is there a shortcut or some options using GUI in pgAdmin 4 to re-run the query of my choice (selected/highlighted query) from history?
Unfortunately, you cannot execute this in View/Edit table mode. However, you can copy the SQL and open a new query tool, paste the query and run it.

View the source for an sql server agent job?

In SQL Management Studio, you can right click on an Agent Job and choose 'Script Job as' -> 'Create to/Drop to', which will reveal the backend code for the agent job.
Is there a script I can execute which would generate this code as well?
I've been searching for details on this, but all I can find so far is references for viewing the script via SQL Management Studio (Example 1, Example 2, Example 3).
If anyone could point me in the proper direction containing ANY details on how to query for a creation script, that would be awesome.
Running a Profiler Trace while running the 'Script Job as' -> 'Create to' reveals a set of SQL statements that you could mimic:

Need script to change sql server job step properties

currently im using Sql server 2008 r2 (will soon be upgrading to 2014). I need some help in changing job step properties using script.
I have around 20 jobs with each job having 4 steps.
I'm trying to change the below highlighted option using sql server script. Because manually changing all these options is a difficult task.
Please help me in writing script to remove the output log path, uncheck append to log, check log to table and check append log to table options.
I got the script
EXEC msdb.dbo.sp_update_jobstep #job_id=N'5e998659-8539-45d2-bf4f-874375c0a111', #step_id=1 ,
#output_file_name=N'',
#flags=16

SQL Server : automatically executed Functions

Is there a way to tell SQL Server to run a function (e.g. deleting datasets which were created half a year ago) after a certain time (every day, every week...) without any third-party apps?
Ty, guys.
Create a stored procedure that will done all the things you want, and then schedule this store procedure to run after some specific time.
To do this you can use the "SQL Server Agent" . To know how SQL server Agent configured and run
please go through the following way
Expand the SQL Server Agent node and right click the Jobs node in SQL Server Agent and select 'New Job'
In the 'New Job' window enter the name of the job and a description on the 'General' tab.
Select 'Steps' on the left hand side of the window and click 'New' at the bottom.
In the 'Steps' window enter a step name and select the database you want the query to run against.
Paste in the T-SQL command you want to run into the Command window and click 'OK'.
Click on the 'Schedule' menu on the left of the New Job window and enter the schedule information (e.g. daily and a time).
Click 'OK' - and that should be it.

SQL Agent Command Line Not Saved

I have a SSIS package I am trying to schedule. I create a new job under SQL Server Agent. On the Command line tab of the jobstep, I choose "Edit the command-line manually".
The changes are retained as I switch from tab to tab within the job step but whenever I exit and save the job, the changes are lost.
Any ideas what's going on?
I'm on SQL Server 2008.
This is a confirmed bug, but here's a workaround that my team uses:
1) Script the create job statement (without your edits)
2) Delete the job from SQL Agent
3) Perform your edits in the create script
4) Execute the create job
This will allow you to keep your manually modified command line options.
There is a bug with the Set Values properties in SQL Server Agent for SSIS packages. You need to save the job step while still on the tab I think(?). I'll see if I can remember and reproduce the steps, but you're not going crazy. ;)
You may need to click "OK" for the job step, and "OK" for the job before moving on to any other changes in the job.
try a copy save as on the package and save change the protection level to encrypt sensitive data with password
I had the same issue when trying to append /DumpOnError to the command line tab of the only step in a job. What I realized was that the change was really performed. And I found it out by generating the "create job" script. What was happening then? Well, it seems as if in the edit box of the command line tab you always got the "default" configuration, however the real one is. I checked it on three installations. 2008 standard, 2012 enterprise and 2017 enterprise.

Resources