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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Execution of Store Procedure

Author  Topic 

abc
Starting Member

48 Posts

Posted - 2001-12-16 : 22:19:47
Hi guru,
Could you tell me the steps execution of a store procedure in server start from it's first creating, call to execute for the first time and reuse when it's call again.

Thanks for your attention

nr
SQLTeam MVY

12543 Posts

Posted - 2001-12-17 : 08:10:07
On creation it will syntax check and try to resolve some objects.
If the objects are not there it may give an error (columns), warning (stored procs) or success return (tables).

On first run it will generate an execution plan - which may or may not resolve all the objects but will fail if it tries to access non-existent objects.
The execution plan consists of a query plan and an execution contex which is specific to the data with which the SP is being called.
This is held in memory for subsequent calls until a used object is changed or the data distribution changes and forces a recompile or it is purged.
Execution plans can be recreated on each call using the recompile option or if objects are transient (temp tables) and not created within the SP.

Note that the plan can be confused by changing objects in another database as it may not spot the change and the object ID referenced may now point to an incorrect object.


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

hande
Starting Member

8 Posts

Posted - 2001-12-17 : 08:21:16
Well, same from me:

One dickhead ( :) ) asked me about stored and function. He thought it was same type of programming as ordinary javascripting.

By the way, Its not possible to intgrate VB/ADO and ASP/ADO: First: You have to know how you can optimize (i.e. get right indexes, use appropriate db options etc. )

After that you might think considering VB/ASP.

Go to Top of Page

abc
Starting Member

48 Posts

Posted - 2001-12-18 : 22:42:23
quote:

On creation it will syntax check and try to resolve some objects.
If the objects are not there it may give an error (columns), warning (stored procs) or success return (tables).

On first run it will generate an execution plan - which may or may not resolve all the objects but will fail if it tries to access non-existent objects.
The execution plan consists of a query plan and an execution contex which is specific to the data with which the SP is being called.
This is held in memory for subsequent calls until a used object is changed or the data distribution changes and forces a recompile or it is purged.
Execution plans can be recreated on each call using the recompile option or if objects are transient (temp tables) and not created within the SP.

Note that the plan can be confused by changing objects in another database as it may not spot the change and the object ID referenced may now point to an incorrect object.


==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.



Thanks Mr nr for help. But I have problem when using recompile option, I don't understand what is the defferent between re create execution plan and recompile procedure. (I don't uderstand the meaning of WITH RECOMPILE option) I saw there is no defferent in result of a store procedure when I use or not use RECOMPILE option. For example I have a store procedure :

Create proc proc1

@para1 int = Null,
@para2 int = Null

as

Insert testtable values (@para1,@para2)

Select * from testtable

Go

Fist I not use WITH RECOMPILE in SP, and I call SP with

Exec proc1 12,12
I'll get a new row of values (12,12)

recall SP with
Exec proc1 15,15
I get a new row of values (15,15) insert to testtable too.

Then I add WITH RECOMPILE in SP and try to call SP two times with different values for each time. I get the result as the first time, when I not use WITH RECOMPILE option. Ummmm I really don't understand when to use RECOMPILE and when not.

Thanks for your attention
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2001-12-19 : 07:45:40
Recompile will force it to recreate the plan and check all the objects and statistics again.
It is useful if objects change and the change is not picked up by dependencies.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -