Script to Automatically Run SQL File - sql

I want a schedule job to run a function/Sql File in SQL Developer without using scheduler in orcale since I only have limited access to the database. Since my function always deletes when database refresh I need to run my function again. I want it to not manually run my sql file. Is this possible using unix script or is there any program I could use for fhis.
P.S It's okay if I need to trigger its using button or something as long as I don't need to run it every refresh of the database. Thanks

Related

SQL Server database : amalgamate 90 database update scripts into a single script

I have an application that has been released for several years. I have updated the SQL Server database around 90 times and each time I have created an update SQL script, so when the user runs the new software version the database is updated.
I would like to amalgamate all the updates into a single SQL script to make deployment faster and simpler, is there an easy way to do this? I presume I could simply grab the latest database after it has run through all 90 updates via SQL Server Management Studio?
EDIT
For clarification; the software I wrote automatically applies new database updates when the user downloads the latest version. This is done via C# / .Net and look for an embedded sql script on startup in the format XX_update.sql calling each script one by one i.e.
1_update.sql - this creates the tables and initial data etc. This was my initial release database.
2_update.sql - updates to the initial database such as adding a new SP or changing column datatype etc
3_update.sql
4_update.sql
...
90_update.sql (4 years and lots of program updates later!).
Ideally, I would install my software and create a brand new database running through all 90 update scripts. Then take this database and convert it into a script which I can replace all 90 scripts above.
This is too long for a comment.
There is no "easy" way to do this. It depends on what the individual updates are doing.
There is a process you can follow in the future, though. Whenever an update occurs, you should maintain scripts both for incremental updates and for complete updates. You might also want to periodically introduce major versions, and be able to upgrade to and from those.
In the meantime, you'll need to build the complete update by walking through the individual ones.
I use a similar system at work and while I prefer to run the scripts separately I have amalgamated several scripts sometimes when they have to be deployed by another person with no problem.
In SQL Server the rule is that as long as you separate the scripts by go and use SQL Server Management Studio or another tool that process the batch separator properly there is no problem in amalgamating it, because it would look like separate scripts to SQL Server (instead of being sent to SQL Server as a one big script the tool send it in batches using the go as the batch separator).
The only problem is that if you have an error in the middle of the script, the tool would continue sending the rest of batches to the server (at least by default, maybe there is an option for changing this). That is why I prefer when possible using a tool to run then separately, just to err on the safer side and stop if there is a problem and locate easily the problematic command.
Also, for new deployments your best option is what you say of using a database that is already updated instead of using the original one and apply all the updates. And to prevent being in this situation again you can keep a empty template database that is not used for any testing and update it when you update the rest of databases.
Are you running your updates manaually on the server. Instead, you can create a .bat file, powershell script or a exe. Update scripts in your folder can be numbered. The script can just pick up updates one by one and execute it over the database connection instead of you doing it.
If you have multiple script files and you want them to combine into one,
rename these as txt, combine, rename the resulting file as sql.
https://www.online-tech-tips.com/free-software-downloads/combine-text-files/
This is easy. Download SQL Server Data Tools and use that to create the deployment script. If there's no existing database, it will create all the objects, and if targeting an older version it will perform a diff against the target database and create scripts that create the missing objects, and alter the existing ones.
You can also generate scripts for the current version using SSMS, or use SSMS to take a backup, and use a restore to in an install.

Schedule creation of a stored procedure

I have a Test database which is overwritten each week by a fresh new production copy.
But we have changes in our Test environment which I script in manually each Monday morning after the copy is created.
Is there a way to schedule script code to run which can generate my objects and data changes eg new stored procedures etc.
The Job scheduler in SQL Server can import a SQL script, but it's not dynamic I need something that I can use in future where it will read in the script each time before it's run and pick up any changes.
I suggest you create a SSIS package and use SMO inside a script component to generate DDL.
This link may help you a little bit.
Using SMO is very easy and straight forward
SMO tutorial

Run SQL Process at specific time

I'm trying to build a background process that will check and execute a stored procedure (SQL Server 2008R2) that users will schedule on a UI application. I don't want to create a job, I want to handle it myself. So I was planning to run a check every 2 secs for example and check if there is process that rich the specific time and run it.
Is there any better way to do it?
If you don't want to set up a task within SQL Server, you could write an app that makes the DB call, then schedule that app through Windows Task Scheduler.

Running Sql Scripts On The Start Of The Application

Hi Guys i wanna know how to run few sql script on our application startup
i am using windows Forms to create a desktop application and have to use this approach for certain task.
database server used is MS SQL
we have to make a method which call the DB script then script will run and do his work. if your next process is depend on that particular script then you have to first call the script and do your work if your next action is not depend on that script so you can keep those script in thread and you can do your work so it will not take a time to load your start point

can a sql 2005 ssis package be scheduled?

I have a data dump that I manually initiate and I want to automate things now that they are working well. I have a system that exports data into Excel that I ultimately want to import into a SQL table.
I have a ssis package that I used for the import and saved it for re-use later. I just manually ran it and it works well. Now I would like to have it run either when invoked by a file watcher or schedule or some thing so that all I need to do is over-write the excel file and have it trigger the ssis to run its import.
Any ideas on how to make this happen?
SQL Server does its scheduling with SQL Agent, so try creating a schedule in that to do what you want.