sql server - Why is sql stored procedure called a stored procedure -


a few days ago asked question(tel intvw) , drawn blank. said execution plan stored in server called stored procedure. not sure correct.

my research after has shown there plan cache or procedure cache inside of sql server that's dedicated storing execution plans. in that article there reference called compiled plan stub. appears compiled plan stub first created , execution plan created.

so wanted know briefly

  1. what steps happen when create stored procedure?

  2. why stored procedure called stored procedure(if question makes sense)?

if can refer me existing question or other article, should fine.

why stored procedure called stored procedure

because procedure stored in database.

in other languages/environments, procedures can executed aren't stored. compiled in either bytecode or assembler. i.e. procedure not exist in original textual form anymore. original procedure cannot retrieved when created in environments (although reverse engineering can retrieve essence of procedure).

when create stored procedure in sql server, stored in original full-text form, same indentation, same casing, same lines, including comments , all. can retrieve text created stored procedure in entirety.

simplified explanation executing stored procedure

when sql server wants execute stored procedure, first check cache see if has been compiled already. if finds entry in cache (in form of execution plan) use entry execute. if doesn't find entry compile procedure execution plan, store in cache later use, execute using execution plan.

there cases force stored procedure recompiled, e.g. when execution plan cache cleared (schema changes, statistics updates, ...) or when supplying commands compiler force recompilation (stored procedure with recompile, query option option(recompile), ...).


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -