Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @@procid mean?

Problem: I have a query file that have a @@procid statement. I want to know the use and meaning of this. I'm new on this, sorry if it is silly.

Question: On my searches, on this site, I learned that it returns the procedure id of current Transact-SQL module, but what is this? What does "Transact-SQL module" mean? It should not return the remainder of some division(here)? I didn't get the example showed on that page.

Or did I misunderstand this?

like image 659
Lupiyo Avatar asked Dec 08 '22 01:12

Lupiyo


2 Answers

The @@procid is the identifier associated with the current executing stored procedure, trigger, or user defined function. It is an internal number sql server uses to keep track of these items in the system. So with this id you can look up what object is associated with it. So in the following example:

SET @ProcName = OBJECT_NAME(@@PROCID);

Gets the procedure name, because OBJECT_NAME is a function which gets the name from the @@PROCID.

The example is a little contrived, because the question ultimately becomes 'why not just hard code the name?' The point of @@Proc is so that if you don't know what is executing (maybe dynamic code or such), you have a way of determining what is being executed at that point in time without having to hard code that information everywhere.

like image 182
kemiller2002 Avatar answered Dec 16 '22 16:12

kemiller2002


Borrowing from here, Module is a term for a stored procedure, a stored function, a trigger or a view definition. When you create one of these objects in a SQL database, it creates an entry in the system tables, including the table sys.sql_modules. These are given an OBJECT_ID, which you can use to identify them (and which the system function @@PROCID is coded to return).

The second item in your question, the MODULO function, returns the remainder of a division: e.g., three divided by three has a remainder of 0, four divided by three has a remainder of 1, and five divided by three has a remainder of 2.

Though they are worlds apart in terms of use, there is a one-letter difference between the two: the first ends with an 'E' (MODULE), while the second ends in an 'O' (MODULO).

like image 38
AHiggins Avatar answered Dec 16 '22 17:12

AHiggins