Wednesday, 5 April 2017

//--CREATE MAIN TABLE --//

//--CREATE MAIN TABLE --//


CREATE TABLE TEACHERLIST(
NAME VARCHAR(50),
QUALIFICATION VARCHAR(50),
ADD VARCHAR(50)
);

//-- CREATE TABLE WHERE TRIGGER AUTO FIRE ON CHANGE ON MAIN TABLE--//


CREATE TABLE TEACHERLISTOFFICE(
NAME VARCHAR(50),
QUALIFICATION VARCHAR(50),
ADD VARCHAR(50)
);

//------CREATE TRIGGER-----//



SYNTAX FOR INSERT:-


CREATE TRIGGER <TRIGGERNAME> AFTER INSERT ON <TABLENAME> FOR EACH ROW
BEGIN
  INSERT INTO <TABLENAME>
(<NAME_OF_COL_1>,<NAME_OF_COL_2>,<NAME_OF_COL_3>)
VALUES
(<VALUE_OF_COL_1>,<VALUE_OF_COL_1>,<VALUE_OF_COL_1>);

END


EXAMPLE:-


CREATE TRIGGER INSERTDATA AFTER INSERT ON TEACHERLIST FOR EACH ROW
BEGIN
INSERT INTO TEACHERLISTOFFICE
(NAME,QUALIFICATION,ADD) VALUES ('RAM','MBA','DELHI');
END

SYNTAX FOR UPDATE:-


CREATE TRIGGER <TRIGGERNAME> AFTER UPDATE ON <TABLENAME>
FOR EACH ROW
 BEGIN
UPDATE <TABLENAME>
SET
<NAME_OF_COL1>=NEW.<NAME_OF_COL1>
<NAME_OF_COL2>=NEW.<NAME_OF_COL2>
END



EXAMPLE:-


CREATE TRIGGER UPDATEDATA AFTER UPDATE ON TEACHERLIST
FOR EACH ROW
BEGIN
UPDATE TEACHERLISTOFFICE
SET
NAME=NEW.NAME,
QUALIFICATION=NEW.QUALIFICATION,
ADD=NEW.ADD;
END




//--CREATE STORE PROCEDURE--//



SYNTAX FOR STORE PROCEDURE:-

CREATE PROCEDURE <PROCEDURE_NAME>()
BEGIN
         ----WRITE SCRIPT HERE----
END


EXAMPLE OF STORE PROCEDURE:-


CREATE PROCEDURE GETDETAILS_TEACHER()
BEGIN
SELECT * FROM TEACHERLIST;
END


//-- CALLING OF STORE PROCEDURE --//


CALL <PROCEDURE_NAME>();



//--EXAMPLE OF CALLING OF STORE PROCEDURE--//


CALL GETDETAILS_TEACHER();

No comments:

Post a Comment