Cross Join: =========== When we want to retrieve the data or info by joining the rows of two tables we can use "cross join". Ex: by joining the row-1 of table-1 with row1 of table-2 and row-1 of table-1 with row-2 of table-2 ==> cross join syntax: ------- select columns from tabl-1 cross join table-2 order by columns; Scenario: ---------- Generating the weekly menu of the restaurant Solution: --------- 1) create the table with the name of "dayName" by including: dayId day by using the below syntax: create table dayName ( dayId number, day varchar(15) ); 2) create another table with the name of "dishes" by including: dishId dishName by using the below syntax: create table dishes ( dishId number, dishName varchar(30) ); 3) Insert the data into both the tables: by using the below syntax: insert into dayName values(&dayId, &day); insert into dishes values(&dishId, &dishName); 4) Cross join: --------------- select d1.dishName, d2.day from dishes d1 cross join dayName d2 order by d1.dishId, d2.dayId; =================================================================================== Events: ======= => three types of events in SQL: 1) insert 2) update 3) delete Triggers: ========= ==> Trigger is a stored procedure that automatically executes in response to an event. How to create the trigger: -------------------------- Scenario: Employees with Audit Information procedure: ---------- 1) create the tables: create table employees ( eid number primary key, ename varchar(100) not null, dept varchar(50) ); create table emp_audit ( auditId number primary key, eid number, ename varchar(100), auditDate date ); 2) create a sequence for auditId start with '1' and increment by '1' -------------------------------------------------------------------- Syntax: ------- create sequence sequence-name start with start-value increment/decrement by step; create sequence emp_audit_seq start with 1 increment by 1; Note: ---- sequence creation for triggers is optional because we allowed to create the sequence within the trigger definition. 3) create the trigger: ----------------------- Syntax: ------- create or replace trigger trigger-name event-name for each row begin event definition end; / create or replace trigger trigger_emp_insert_audit after insert on employees for each row begin insert into emp_audit values(emp_audit_seq.NEXTVAL, :NEW.eid, :NEW.eName, sysdate); end; /