We have an application in that we have around 10 modules. For each module, we have one sp to populate the data. Our requirement is that after the SP call we need to log in the information in the log table like module name, user name and access time.
To achieve this we have two approaches.
o
We need to write the query to insert the record
into the log table in each Sp
o
We need to write on sp to log the information into the table and we will call this sp in each module sp.
The drawback for approach one is if we made any change in the
logic we need to make the changes in all SP. But in the second approach, we
can make the change in one place only.
Let’s see in this demo how we call one sp from another SP.
We have a log table
CREATE PROCEDURE [dbo].[P_insert_app_audit] @App_nm VARCHAR(50), |
We are calling this SP into the other SP.
CREATE PROCEDURE [dbo].[P_get_productid] @ProductID VARCHAR(20) |
Now we call this SP.
If we see the message we will see that two rows effected.
See it in the log table.
During the execution, if we get any
error in this case we will get the message in the log table.