SQL - Stored Procedures
Stored Procedure is a prepared code that you can save and you can use that code over and over again.
example:
select * from tbemp;
Stored Procedure Syntax:
create PROCEDURE pro_name
AS
sql_query
GO;
Execute the Stored Procedure:
EXEC procedure_name;
Example:
CREATE PROCEDURE getAllEmployee
AS
select * from tbemp
GO;
DELIMITER $$
CREATE PROCEDURE `allEmp`()
BEGIN
select * from tbEmp;
END;
Excecution:
Exce getAllEmployee; //MSSQL
call allEmployees(); // MYSQL
DELIMITER $$
CREATE PROCEDURE `allEmployeeDetail`()
BEGIN
select e.emp_id as ID, e.emp_dept as Department, e.name, s.student_email, s.is_active
from tbEmp e inner join stdn s
on e.emp_id=s.student_id
where s.password_hash!='';
END;
DROP PRocedure allEmployeeDetail;
call allEmployeeDetail();
Comments
Post a Comment