Contents
How can I make a stored procedure faster?
Improve stored procedure performance in SQL Server
- Use SET NOCOUNT ON.
- Use fully qualified procedure name.
- sp_executesql instead of Execute for dynamic queries.
- Using IF EXISTS AND SELECT.
- Avoid naming user stored procedure as sp_procedurename.
- Use set based queries wherever possible.
- Keep transaction short and crisp.
Can we create temporary stored procedure?
Temporary stored procedures are created just like any other SPs; however the name must begin with a hash (#) for a local temporary SP and two hashes (##) for a global temporary stored procedure. Aside from local and global temporary stored procedures, you can also create regular stored procs in tempdb.
Can we create temporary function in SQL Server?
You can’t create temporary functions, no.
Can a stored procedure be run after the first?
I have a second stored procedure that should be run after the first stored procedure runs since it is based on the numbers obtained from this first stored procedure, however it takes longer to run and is for a separate process, so I don’t want to make the user wait while this 2nd stored procedure gets ran.
What happens if I forget the 2nd stored procedure?
Also, the 2nd stored procedure is fairly critical, and forgetting to run it could cause some major problems for our company. Make the 1st procedure set a flag, and setup a recurring job to check for that flag and run if its set, like Jimbo suggested.
How to run stored procedures in parallel database?
Just to be totally explicit: TSQL does not (by itself) have the ability to launch other TSQL operations asynchronously. SQL Agent jobs: Create multiple SQL jobs, and either schedule them to run at the time desired, or start them asynchronously from a “master control” stored proc using sp_start_job.
How to launch a procedure in SQL Server?
You could use service broker together with activation on the queue. With that you could post the parameters for the procedure call on the queue. That takes about as much time as an insert. After the transaction is committed and potentially a few more seconds, activation would automatically call the receiver procedure asynchronously.