Presentation is loading. Please wait.

Presentation is loading. Please wait.

Structured Query Language (SQL). BOOK RELATION TITLEAUTHORPUBLISHERYEARISBN JAWSBENCHLEYHARPER1976003-02-0045 ITKINGRANDOM HOUSE 1989123-45-6798 HYPERIONSIMMONSEOS1990443-27-6645.

Similar presentations


Presentation on theme: "Structured Query Language (SQL). BOOK RELATION TITLEAUTHORPUBLISHERYEARISBN JAWSBENCHLEYHARPER1976003-02-0045 ITKINGRANDOM HOUSE 1989123-45-6798 HYPERIONSIMMONSEOS1990443-27-6645."— Presentation transcript:

1 Structured Query Language (SQL)

2 BOOK RELATION TITLEAUTHORPUBLISHERYEARISBN JAWSBENCHLEYHARPER1976003-02-0045 ITKINGRANDOM HOUSE 1989123-45-6798 HYPERIONSIMMONSEOS1990443-27-6645 SNOW CRASHSTEPHENSONRANDOM HOUSE 1992553-24-667

3 CREATE TABLE SYNTAX CREATE TABLE ( [NOT NULL],... CONSTRAINT PRIMARY KEY ( ) [,] [FOREIGN KEY ( ) REFERENCES ( )] [,] [FOREIGN KEY ( ) REFERENCES ( )]... )

4 SUPPLY DATABASE

5 EMPLOYEE & DEPARTMENT RELATIONS NAMESSNDNAME BOB1123MAIL MIKE1234MAIL TIM3314SECURITY EMPLOYEE DNAMEMGRSSN MAIL1123 SECURITY3314 DEPARTMENT

6 SQL FOR GET NAMES OF DEPARMENT MANAGERS SELECT NAME FROM EMPLOYEE, DEPARTMENT WHEREEMPLOYEE.SSN = DEPARTMENT.MGRSSN

7 NAMESSNDNAME MGRSSN BOB1123MAIL 1123 BOB1123MAILSECURITY3314 MIKE1234MAIL 1123 MIKE1234MAILSECURITY3314 TIM3314SECURITYMAIL1123 TIM3314SECURITY 3314 CARTESIAN PRODUCT OF FROM CLAUSE

8 CARTESIAN PRODUCT FILTERED BY WHERE CLAUSE NAMESSNDNAME MGRSSN BOB1123MAIL 1123 TIM3314SECURITY 3314

9 PROJECT DOWN TO ATTRIBUTES IN SELECT CLAUSE NAME BOB TIM

10 NameAgeSpouseDependents Bob39Becky0 32Bob0 Mike38Carrie0 39Mike0 Kathy34Mark2 34Kathy2 Tim37Stacy0 37Tim0 Pat34Deb0 32Pat0 Jeff34---0 People The PEOPLE Relation

11 NameAge Bob39 Carrie39 Mike38 Stacy37 Tim37 Jeff34 Pat34 Becky32 Deb32 Result SELECT Name, Age FROM People WHERE Dependents = 0 ORDER BY Age DESC, Name ASC Ordering Query Results

12 NameAgeSpouseDependents Bob39Becky0 Carrie39Mike0 Becky32Bob0 Deb32Pat0 Kathy34Mark2 34Kathy2 Pat34Deb0 Jeff34---0 Tim37Stacy0 37Tim0 Mike38Carrie0 People The PEOPLE Relation Partitioned Into Groups SELECT Age, COUNT(*) FROM People GROUP BY Age

13 S#SNAMESTATUSCITYS#P#J#QTY S1Smith20LondonS1P1J1200 S2Jones10ParisS2P3J1400 S3Blake30ParisS3P3J1200 S4Clark20London--- S5Adams30Athens--- Intermediary table for LEFT OUTER JOIN QUERY: SELECT SNAME, P# FROM S, (SELECT * FROM SPJ WHERE J#=‘J1’) SPJ1 WHERE S.S#=SPJ.S# (+)

14 ActionDateActionItemQuantityQuantityTypeCostTotalPerson LEDGER ActionDateActionItemQuantityQuantityTypeCostTotalPerson LEDGER_AUDIT TRIGGERS: LEDGER and LEDGER_AUDIT TABLES

15 create trigger ledger_update before update on LEDGER for each row when ((new.Amount/old.Amount)>1.1) begin insert into LEDGER_AUDIT values (:old.ActionDate, :old.Action, :old.Item, :old.Quantity, :old.QuantityType, :old.Cost, :old.Total, :old.Person); end; TRIGGERS: EXAMPLE

16 TRIGGERS: SYNTAX


Download ppt "Structured Query Language (SQL). BOOK RELATION TITLEAUTHORPUBLISHERYEARISBN JAWSBENCHLEYHARPER1976003-02-0045 ITKINGRANDOM HOUSE 1989123-45-6798 HYPERIONSIMMONSEOS1990443-27-6645."

Similar presentations


Ads by Google