Hey guys, In this blog, I am going to
explain you about stored procedure and how to implement stored procedure in a
SQL Server.
Stored procedure – Stored procedure in SQL is a group of SQL statements that
are stored together in a database. Based on the statements in the procedure and
the parameters you pass, it can perform one or multiple DML operations on the
database, and return value, if any. Thus, it allows you to pass the same
statements multiple times, thereby, enabling reusability.
Assignment - 1:
STEP -1:
In this assignment, we are going to perform the division between two variables using
the stored procedure,
·
First you
have to select a database and inside the database you have to create a
procedure by writing a syntax as given below,
STEP
-2:
To get the result, you need
to execute a query as given below,
exec
sp_test_division 500, 100
Assignment -2:
STEP-1:
·
First
you have to create a database and inside the database you we have to create a
table like test_1 and test_2 and insert some data in both the table and make
sure you have to create an argument @e_id = Employee_ID,
STEP -2:
· Create a database:
STEP -3:
· After that you have to create a table-1 as shown below,
STEP -4:
·
Now
create another table-2 inside the same database as shown below –
STEP -5:
·
Procedure
to create a stored procedure between two tables.
·
First
create a Stored Procedure inside a database, here @e_id int is an argument used to bypass employee ID
STEP -6:
· In below syntax, first you have to
create a Procedure to get a few data of the columns like Employee ID, Employee Name from first table and Department ID from second table
· Also, you have to input a catch command
to get an error message if any error occurred during execution.
STEP -7: To get the result, you need to execute
the last query i.e.
Nice article 👍 thanks for writing it.
ReplyDelete