Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Compiling stored proc?

Author  Topic 

fralo
Posting Yak Master

161 Posts

Posted - 2009-09-01 : 09:20:10
Okay guys, I'm about ready to claw out my eyeballs!

I've written a stored procedure. Now I simply want to compile it onto the database. The only option that I see, though, is to Execute. But this would execute the commands which I don't want.

How can I simply compile the procedure onto the server?

Thank you.

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-01 : 09:54:06
Once the stored peocedure is created, it is saved to the database as an object. There is no such thing as compiling a stored procedure.

Once it is run for the first time, a query plan will be created for it.

Unless you are encrypting the stored proc, there is noting else to do once the CREATE PROCEDURE statement has been run.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-01 : 09:55:02
Script the code and execute it. Like

Create procedure...
.
.


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-09-01 : 10:02:24
Well I need to set this procedure to run as an automated daily process. So tell me if I'm correct here. I will have to execute it manually the first time, and this will save it onto the database?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-09-01 : 10:07:48
quote:
Originally posted by fralo

Well I need to set this procedure to run as an automated daily process. So tell me if I'm correct here. I will have to execute it manually the first time, and this will save it onto the database?


The procedure will be saved. If you want to excute it regularly make use of job

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-01 : 10:08:30
No, not at all. If you have run the script (as in the CREATE PROCEDURE script), then it is already in the database. You can see this by going to Management Studio and looking in the Programability -> Stored Procedures tree under your database.

If you haven't run this script, just run it. It will not run the code, but will parse the code to check for any errors. Once the procedure appears in the tree, then you can schedule a job by going to the SQL Agent and creating a new job to simply Exec that procedure.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2009-09-01 : 10:09:51
The procedure code is stored in the database when you create it. It is compiled or recompiled as needed upon execution. If the procedure is never run, it is never compiled.

To make it run on a daily schedule, you create a SQL Agent job and set the schedule. See Books Online under "jobs".

edit: yeah, what they said
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-09-01 : 10:16:41
quote:
Originally posted by RickD


If you haven't run this script, just run it. It will not run the code, but will parse the code to check for any errors.


I believe this clears up my confusion. I've written the code and now want to save it onto the database. If I click 'Execute', it WILL NOT execute my code, just simply save it onto the database and check for syntax errors. This is what I meant by 'compiling' it, even if there is no such thing as you've said. I only want the code within it to be 'executed' (i.e. data manipulation) once I schedule it.
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2009-09-01 : 10:23:31
Yeah, thats what you'll get, as long as you have the following structure:

CREATE PROCEDURE <procname>
<Variables>
AS
<your code here>
GO
Go to Top of Page

fralo
Posting Yak Master

161 Posts

Posted - 2009-09-01 : 10:27:22
Thanks so much for all of your help.
Go to Top of Page
   

- Advertisement -