T-sql – Create a T-sql script JOB SQL-2012 and scheduled

t-sql

I would like to create a T-sql script and scheduled. My goal is create all my databases (4 databases) and when the QA or DEV team need to test something, they can use these databases.
The problem is that I don´t have other server so I have to use the same server, for example I have a database called AUXDB, so I need to create a new database as PRE_AUXDB.
I have been creating all the scripts per each dabatase (just structure) but I need to know, how to create a header script to execute each script.
I hope you can understand my request.

Thank you in advance.
Raúl

Best Answer

Ok, after yor comment it is clear. I will do the following:

  1. Create a new DB called SERVICE, MAINTANANCE, etc.
  2. Inside it create a stored procedures for different steps - drop old DB, create new DB, populate new DB. You can make all that in one procedure also.
  3. Create one procedure which will execute others - step by step (if you not implemented all logic in one procedure).
  4. Creata a job with permissions - inside it strat main procedure. Or tell DEV team to use main procedure inside new DB (with appropriate permissions).