├── .gitignore ├── 1_Basic_intro ├── Relational Table.pdf ├── Simple Tests │ ├── sql1_selection.sql │ ├── sql1_deletion.sql │ ├── sql1_update.sql │ └── sql1_insertion.sql ├── Exercise1(re-do).sql └── Exercise1.sql ├── 2_SQL_Queries ├── List of queries.pdf ├── Tables │ ├── AllTheBooks.sql │ └── FlyWithOther.sql ├── Block1 (AllTheBooks Table).sql └── Block2 (FlyWithOther Table).sql ├── 3_Triggers:Procedures ├── Assigmnet 5.docx ├── Example DBMS_output.txt ├── 2_Deparments_employees_changes.sql ├── 3_Exercise2_PL_SQL.sql ├── 1_Contracts_Routes_Triggers.sql └── 4_ScriptExercises PLSQL.sql ├── Readme.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /1_Basic_intro/Relational Table.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/1_Basic_intro/Relational Table.pdf -------------------------------------------------------------------------------- /2_SQL_Queries/List of queries.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/2_SQL_Queries/List of queries.pdf -------------------------------------------------------------------------------- /2_SQL_Queries/Tables/AllTheBooks.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/2_SQL_Queries/Tables/AllTheBooks.sql -------------------------------------------------------------------------------- /3_Triggers:Procedures/Assigmnet 5.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/3_Triggers:Procedures/Assigmnet 5.docx -------------------------------------------------------------------------------- /2_SQL_Queries/Block1 (AllTheBooks Table).sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/2_SQL_Queries/Block1 (AllTheBooks Table).sql -------------------------------------------------------------------------------- /1_Basic_intro/Simple Tests/sql1_selection.sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/1_Basic_intro/Simple Tests/sql1_selection.sql -------------------------------------------------------------------------------- /2_SQL_Queries/Block2 (FlyWithOther Table).sql: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ferreiro/SQL-Oracle-databases/HEAD/2_SQL_Queries/Block2 (FlyWithOther Table).sql -------------------------------------------------------------------------------- /1_Basic_intro/Simple Tests/sql1_deletion.sql: -------------------------------------------------------------------------------- 1 | -- This code should delete a Theme tendría que también borrrar la 2 | -- referencia de Clasification. MIrar cómo queda clasification después de borrar y 3 | -- meter las modificaciones que haga falta 4 | DELETE FROM Theme 5 | WHERE IdTheme=0; 6 | 7 | DELETE FROM Publication 8 | WHERE NPublisher IN (SELECT Name from Publisher); 9 | 10 | -- Esto tendría que borrar la entrada de Clasification 11 | DELETE FROM Publication 12 | WHERE ISBN='B232'; 13 | -------------------------------------------------------------------------------- /1_Basic_intro/Simple Tests/sql1_update.sql: -------------------------------------------------------------------------------- 1 | SELECT LANGUAGE 2 | FROM PUBLICATION 3 | GROUP BY LANGUAGE 4 | HAVING COUNT(LANGUAGE)>=2; 5 | 6 | 7 | -- Update theme description where ThemeID is 0 8 | UPDATE Theme 9 | SET Description='Esto es una nueva Description hahahah' 10 | WHERE IDTHEME=0; 11 | 12 | -- Update each theme that ID doesn't appear on classification 13 | UPDATE Theme 14 | SET Description="Nueva Description para el segundo tema" 15 | WHERE IDTheme NOT IN (SELECT IDTheme FROM Clasification); -------------------------------------------------------------------------------- /3_Triggers:Procedures/Example DBMS_output.txt: -------------------------------------------------------------------------------- 1 | Following you can find an example that you can follow to print headers and data in the PL/SQL blocks 2 | 3 | You can declare a variable for using a tabular character 4 | 5 | TB constant varchar2(1):=CHR(9); 6 | 7 | You can find the functionality of the functions rpad(string,lenght,character)and lpad(string,lenght,character) in the slides. 8 | 9 | dbms_output.put_line(lpad('Numb',8,' ')||TB||rpad('Title',60,' ')||TB||lpad('Mark',12,' ')); 10 | dbms_output.put_line(rpad('-',85,'-')); 11 | It prints 12 | 13 | Numb Title Mark 14 | ---------------------------------------------------------------------------------------- 15 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # SQL Oracle databases 2 | 3 | More than 40 exercises on Basic Queries, Advanced queries, Storaged Procedures (PL) and Triggers on SQL for Oracle Database. 4 | 5 | This repository was created for the course "Databases" that was taken place during October 2015 - January 2016 in Madrid. 6 | 7 | The repository is divided into 3 main folders. 8 | 9 | 1. Basic_intro: given a relational model I had to implement on SQL (creating the tables, constraints and the rest of the relational stuff). 10 | 2. SQL_Queries: contains more than 30 queries. From basic ones to more complex. 11 | 3. Triggers_Procedures: some exercises on storaged procedures and triggers (functions that get executed when some condition is done like insert, delete, update...). 12 | 13 | ### Credits 14 | All the code in this repository has been made by the following contributors: 15 | - Jorge Ferreiro (@ferreiro) 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jorge Ferreiro. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /1_Basic_intro/Simple Tests/sql1_insertion.sql: -------------------------------------------------------------------------------- 1 | CREATE SEQUENCE ThemesID_Sequence 2 | MINVALUE 0 3 | START WITH 0 4 | INCREMENT BY +1 5 | NOCACHE; 6 | 7 | /********************************************/ 8 | -- Themes: IdTheme, Description */ 9 | INSERT INTO Theme VALUES(ThemesID_Sequence.NEXTVAL, 'Amazing theme'); 10 | INSERT INTO Theme VALUES(ThemesID_Sequence.NEXTVAL, 'Amazing theme 2'); 11 | INSERT INTO Theme VALUES(ThemesID_Sequence.NEXTVAL, 'Amazing theme 3'); 12 | 13 | -- Publishers: Name, Address, Phone */ 14 | INSERT INTO Publisher VALUES('McGrah', 'Sol 20', 600400330); 15 | 16 | -- Publication: ISBN, Title, Language, NamePublisher */ 17 | INSERT INTO Publication VALUES('A232', 'Zero to', 'English', 'McGrah'); 18 | INSERT INTO Publication VALUES('B232', 'Pull and bear', 'English', 'McGrah'); 19 | INSERT INTO Publication VALUES('C232', 'YOOO', 'English', 'McGrah'); 20 | INSERT INTO Publication VALUES('D232', 'HAHAHAA', 'English', 'McGrah'); 21 | INSERT INTO Publication VALUES('E232', 'OXFORD', 'English', 'McGrah'); 22 | 23 | -- Clasifications: ISBN and ThemeID */ 24 | INSERT INTO Clasification VALUES('A232', 0); 25 | INSERT INTO Clasification VALUES('B232', 1); 26 | INSERT INTO Clasification VALUES('B232', 2); 27 | INSERT INTO Clasification VALUES('C232', 3); 28 | INSERT INTO Clasification VALUES('C232', 4); 29 | INSERT INTO Clasification VALUES('D232', 5); 30 | -------------------------------------------------------------------------------- /3_Triggers:Procedures/2_Deparments_employees_changes.sql: -------------------------------------------------------------------------------- 1 | CREATE SEQUENCE CHANGEID 2 | INCREMENT BY 1 3 | START WITH 1; 4 | 5 | drop table Departments cascade constraints; 6 | drop table Employees cascade constraints; 7 | drop table Changes cascade constraints; 8 | 9 | CREATE TABLE Departments (CodDept CHAR(5) PRIMARY KEY, 10 | Name VARCHAR(100)); 11 | 12 | CREATE TABLE Employees (SSN CHAR(9) PRIMARY KEY, 13 | Name VARCHAR(100), 14 | CodDept CHAR(5) REFERENCES Departments on delete set NULL, 15 | Salary NUMBER(4,0)); 16 | 17 | CREATE TABLE Changes(IdChange VARCHAR(10) PRIMARY KEY, 18 | UserId VARCHAR(8), 19 | OldSalary NUMBER(4,0), 20 | NewSalary NUMBER(4,0)); 21 | 22 | INSERT INTO Departments VALUES('1', 'Department 1'); 23 | INSERT INTO Departments VALUES('2', 'Department 2'); 24 | INSERT INTO Departments VALUES('3', 'Department 3'); 25 | 26 | INSERT INTO Employees VALUES('123456789', 'PACO', '1', 2000); 27 | INSERT INTO Employees VALUES('123455789', 'Luis', '1', 0); 28 | INSERT INTO Employees VALUES('123455789', 'Luis', '1', 1000); 29 | INSERT INTO Employees VALUES('013455789', 'Sara', '2', 1000); 30 | INSERT INTO Employees VALUES('023455789', 'Pularda', '2', 3000); 31 | 32 | UPDATE Employees 33 | SET SALARY=2000 34 | WHERE SSN='123456789'; 35 | 36 | /* 37 | Write a trigger that records in the table Changes any update of the salary of the employees. 38 | The trigger must store the user, the date of the change, and both the salary before the change and the updated salary. 39 | The ID will be obtained from a sequence called SEQChanges. 40 | */ 41 | 42 | create or replace TRIGGER UpdateRecords 43 | after update of Salary on Employees 44 | for each row 45 | begin 46 | INSERT INTO Changes values (CHANGEID.NEXTVAL, USER(), :OLD.Salary, :NEW.Salary); 47 | end; 48 | 49 | /* 50 | Write a stored procedure that lists for each department the name and salary of each employee whose salary is lower than the average of the department. 51 | For each department the procedure must show the total amount of these salaries by department. 52 | */ 53 | create or replace PROCEDURE MY_SALARIESPROC 54 | IS 55 | 56 | CURSOR cursorDeparment is 57 | SELECT Name, SALARY 58 | FROM EMPLOYEES E 59 | WHERE SALARY<( 60 | SELECT AVG(SALARY) 61 | FROM EMPLOYEES 62 | WHERE CodDept=E.CodDept 63 | GROUP BY (CodDept) 64 | ); 65 | 66 | AUX NUMBER:=0; 67 | v_name VARCHAR(100); 68 | 69 | rEmployee cursorDeparment%ROWTYPE; 70 | 71 | BEGIN 72 | 73 | OPEN cursorDeparment; 74 | 75 | LOOP 76 | FETCH cursorDeparment into rEmployee; 77 | EXIT WHEN cursorDeparment%NOTFOUND; 78 | dbms_output.put_line(rEmployee.Name || ', ' || rEmployee.Salary); 79 | END LOOP; 80 | 81 | CLOSE CursorDeparment; 82 | 83 | END; -------------------------------------------------------------------------------- /1_Basic_intro/Exercise1(re-do).sql: -------------------------------------------------------------------------------- 1 | drop table Publisher cascade constraints; 2 | drop table Publication cascade constraints; 3 | drop table Theme cascade constraints; 4 | drop table Clasification cascade constraints; 5 | drop table Book cascade constraints; 6 | drop table Biblioteca cascade constraints; 7 | drop table Member cascade constraints; 8 | drop table BookCopy cascade constraints; 9 | drop table Journal cascade constraints; 10 | drop table JournalCopy cascade constraints; 11 | drop table Subscription cascade constraints; 12 | 13 | create table Publisher( 14 | Name varchar(28) PRIMARY KEY NOT NULL, 15 | Address varchar(40), 16 | Phone number(9, 0) 17 | ); 18 | 19 | create table Publication( 20 | ISBN varchar(13) PRIMARY KEY NOT NULL, 21 | Title varchar(25), 22 | Language varchar(25), 23 | NPublisher varchar(28), 24 | foreign key(NPublisher) references Publisher 25 | ); 26 | 27 | create table Theme( 28 | IDTheme varchar(15) PRIMARY KEY NOT NULL, 29 | Description varchar(140) 30 | ); 31 | 32 | create table Clasification( 33 | ISBN varchar(13), 34 | IDTheme varchar(15), 35 | foreign key(IDTheme) references Theme, 36 | foreign key(ISBN) references Publication, 37 | constraint ISBN_ID_PK primary key(ISBN, IDTheme) 38 | ); 39 | 40 | create table Book( 41 | ISBN varchar(13) primary key not null, 42 | edition number(2), 43 | ed_date date, 44 | foreign key(ISBN) references Publication 45 | ); 46 | 47 | create table Biblioteca( 48 | Postal_Code number(5) primary key not null 49 | ); 50 | 51 | create table Member( 52 | NMember number primary key, 53 | Name varchar(20), 54 | Email varchar(33), 55 | Postal_Code number(5), 56 | foreign key(Postal_Code) references Biblioteca /* Relate postal code with Biblioteca*/ 57 | ); 58 | 59 | create table BookCopy( 60 | ISBN varchar(13), 61 | PC number(5), 62 | Num number(2), 63 | Adq_Date date, 64 | NMember number null, /* PONER LO DE NULLABLE*/ 65 | BorrowDate date null, 66 | 67 | foreign key(ISBN) references Book, 68 | foreign key(PC) references Biblioteca, 69 | foreign key(NMember) references Member, 70 | constraint ISBN_Postalcode_PK primary key (ISBN, PC) /* Join ISBN and PC as the primary key*/ 71 | ); 72 | 73 | create table Journal( 74 | ISBN varchar(13) primary key, 75 | Frecuency number, 76 | 77 | foreign key(ISBN) references Publication 78 | ); 79 | 80 | create table Subscription( 81 | ISBN varchar(13), 82 | PC number(5), 83 | Sub_Date date NULL, 84 | foreign key(ISBN) references Journal, 85 | foreign key(PC) references Biblioteca, 86 | constraint ISBN_PK primary key(ISBN, PC) 87 | ); 88 | 89 | create table JournalCopy( 90 | ISBN varchar(13), 91 | PostalCode number(5), 92 | Num number(2), 93 | NMember number null, 94 | 95 | foreign key(ISBN, PostalCode) references Subscription, 96 | foreign key(NMember) references Member, 97 | constraint ISBN_PC_Num_PK primary key(ISBN, PostalCode, Num) /* ???: key(ISBN, PostalCode, Num) */ 98 | ); 99 | -------------------------------------------------------------------------------- /3_Triggers:Procedures/3_Exercise2_PL_SQL.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Contracts(Ref VARCHAR(10) PRIMARY KEY, 2 | Organization VARCHAR(100), 3 | ContDate DATE, 4 | NumRoutes NUMBER(2,0)); 5 | 6 | CREATE TABLE Routes(Ref VARCHAR(10) REFERENCES Contracts ON DELETE CASCADE, 7 | Origin VARCHAR(50), 8 | Destination VARCHAR(50), 9 | Vehicle VARCHAR(20), 10 | PRIMARY KEY (Ref, Origin, Destination)); 11 | 12 | /*insert into Routes values ('0123456789', 'Lisboa', 'oporto', 'mercedes'); */ 13 | /*insert into Routes values ('0123456789', 'Lisboa', 'Madrid', 'mercedes'); */ 14 | /*DELETE FROM Routes 15 | WHERE Ref='0123456789' && Origin='Lisboa' && Destination='Madrid' && Vehicle='mercedes';*/ 16 | 17 | /* Creating a procedure */ 18 | create or replace 19 | PROCEDURE myContractProcedure 20 | (ReferenceContract IN VARCHAR) 21 | IS 22 | v_numberRoutes number:= 0; 23 | v_noValues boolean:= false; 24 | v_organizationName contracts.organization%type:= 'Name'; 25 | noRoutes Exception; 26 | 27 | BEGIN 28 | 29 | /* Print organization name */ 30 | /* Cuando no exista la referencia que te pasan por parámetro, esto 31 | va a lanzar una excepción de no_Data_found, porque te lanzará NULL 32 | */ 33 | SELECT Contracts.Organization INTO v_organizationName 34 | FROM Contracts 35 | WHERE Contracts.REF=ReferenceContract; 36 | 37 | /* Select the number of references that appears on Routes given a referenceContract pass by value */ 38 | Select NVL(COUNT(ReferenceContract), 0) into v_numberRoutes 39 | from Routes 40 | where Ref=ReferenceContract; 41 | 42 | if (v_numberRoutes <= 0) then 43 | Raise noRoutes; 44 | else 45 | /* Count is greater than 0. 46 | Update value of refernce contracts */ 47 | UPDATE Contracts 48 | SET NumRoutes = v_numberRoutes 49 | WHERE Contracts.Ref=ReferenceContract; 50 | end if; 51 | 52 | /* Print the total number of routes founded */ 53 | DBMS_OUTPUT.PUT_LINE(v_organizationName || ' ' ||v_numberRoutes ); 54 | 55 | EXCEPTION 56 | WHEN noRoutes then 57 | DBMS_OUTPUT.PUT_LINE('No routes for this reference'); 58 | WHEN NO_DATA_FOUND then 59 | DBMS_OUTPUT.PUT_LINE('Reference does not exist.'); 60 | END; 61 | 62 | 63 | /* Creating a trigger */ 64 | CREATE OR REPLACE TRIGGER organizationTrigger 65 | AFTER INSERT OR DELETE OR UPDATE ON Routes 66 | for each row 67 | 68 | BEGIN 69 | 70 | IF DELETING THEN 71 | UPDATE Contracts 72 | SET NumRoutes = NumRoutes-1 73 | WHERE Contracts.Ref=:old.Ref; 74 | ELSIF INSERTING THEN 75 | UPDATE Contracts 76 | SET NumRoutes = NumRoutes+1 77 | WHERE Contracts.Ref=:new.Ref; 78 | END IF; 79 | 80 | END; 81 | -------------------------------------------------------------------------------- /3_Triggers:Procedures/1_Contracts_Routes_Triggers.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE Contracts(Ref VARCHAR(10) PRIMARY KEY, 2 | Organization VARCHAR(100), 3 | ContDate DATE, 4 | NumRoutes NUMBER(2,0)); 5 | 6 | 7 | CREATE TABLE Routes(Ref VARCHAR(10) REFERENCES Contracts ON DELETE CASCADE, 8 | Origin VARCHAR(50), 9 | Destination VARCHAR(50), 10 | Vehicle VARCHAR(20), 11 | PRIMARY KEY (Ref, Origin, Destination)); 12 | 13 | INSERT INTO CONTRACTS VALUES('123', 'FDI', '1/1/1994', 0); 14 | INSERT INTO Routes VALUES('123', 'MADRID', 'VALENCIA', 'SEAT'); 15 | INSERT INTO Routes VALUES('123', 'MADRID', 'SALAMANCA', 'SEAT'); 16 | INSERT INTO Routes VALUES('123', 'MADRID', 'BILBAO', 'SEAT'); 17 | 18 | 19 | /* 20 | Write a stored procedure with a reference contract as input parameter. 21 | 22 | 1. The procedure must update the information in NumRoutes, according to the number of routes associated with the contract. 23 | 2. The procedure also must print the name of the organization and the total number of associated routes. You must declare 24 | an exception that is thrown to show a message if the reference does not have associated any route. 25 | */ 26 | 27 | create or replace PROCEDURE updateNumRoutes 28 | (contractReference IN VARCHAR) 29 | IS 30 | -- Get the number of routes associated with a contract 31 | newNumRoutes Contracts.NumRoutes%TYPE:= 0; 32 | orgName varchar(100); 33 | totalRoutes number:= 0; 34 | noAssociateRoute exception; 35 | 36 | BEGIN 37 | 38 | SELECT count(Ref) INTO newNumRoutes 39 | from Routes 40 | where Ref=contractReference; 41 | 42 | if (newNumRoutes> 0) then 43 | UPDATE Contracts 44 | SET NumRoutes=newNumRoutes; 45 | else 46 | raise noAssociateRoute; 47 | end if; 48 | 49 | -- total number of associated routes 50 | SELECT COUNT(DISTINCT Ref) INTO totalRoutes 51 | FROM Contracts 52 | WHERE Ref=contractReference; 53 | 54 | -- name of the organization 55 | SELECT DISTINCT ORGANIZATION INTO orgName 56 | FROM CONTRACTS 57 | WHERE Ref=contractReference; 58 | 59 | DBMS_OUTPUT.PUT_LINE('Organization name ' || totalRoutes); 60 | DBMS_OUTPUT.PUT_LINE('Total Routes is ' || orgName); 61 | 62 | EXCEPTION 63 | WHEN noAssociateRoute then 64 | DBMS_OUTPUT.PUT_LINE('No routes for this reference'); 65 | END; 66 | 67 | /* Creating a trigger */ 68 | /* 69 | CREATE OR REPLACE TRIGGER organizationTrigger 70 | AFTER INSERT OR DELETE OR UPDATE ON Routes 71 | for each row 72 | 73 | BEGIN 74 | 75 | IF DELETING THEN 76 | UPDATE Contracts 77 | SET NumRoutes = NumRoutes-1 78 | WHERE Contracts.Ref=:old.Ref; 79 | ELSIF INSERTING THEN 80 | UPDATE Contracts 81 | SET NumRoutes = NumRoutes+1 82 | WHERE Contracts.Ref=:new.Ref; 83 | END IF; 84 | 85 | END; 86 | */ 87 | -------------------------------------------------------------------------------- /1_Basic_intro/Exercise1.sql: -------------------------------------------------------------------------------- 1 | DROP TABLE Theme CASCADE constraints; 2 | DROP TABLE Clasification CASCADE constraints; 3 | DROP TABLE Publisher CASCADE constraints; 4 | DROP TABLE Publication CASCADE constraints; 5 | 6 | DROP TABLE Book CASCADE constraints; 7 | DROP TABLE Biblioteca CASCADE constraints; 8 | DROP TABLE Journal CASCADE constraints; 9 | DROP TABLE Subscription CASCADE constraints; 10 | 11 | DROP TABLE Member CASCADE constraints; 12 | DROP TABLE JournalCopy CASCADE constraints; 13 | DROP TABLE BookCopy CASCADE constraints; 14 | 15 | /* 16 | * Creatign all neccesary tables for Publication 17 | * before creating Publication table: 18 | * - Theme 19 | * - Clasification 20 | * - Publisher 21 | */ 22 | CREATE TABLE Theme ( 23 | IdTheme NUMBER, 24 | Description VARCHAR(100), 25 | CONSTRAINT TME_PK PRIMARY KEY(IdTheme) 26 | ); 27 | 28 | CREATE TABLE Publisher( 29 | Name VARCHAR(20), 30 | Address VARCHAR(30), 31 | Phone NUMBER(9), 32 | 33 | CONSTRAINT pus_PK PRIMARY KEY(Name) 34 | ); 35 | 36 | CREATE TABLE Publication( 37 | ISBN VARCHAR(13), 38 | Title varchar(30), 39 | Language varchar(20), 40 | NPublisher varchar(20), 41 | 42 | CONSTRAINT pub_PK PRIMARY KEY(ISBN), 43 | CONSTRAINT pub_FK FOREIGN KEY(NPublisher) REFERENCES Publisher 44 | ); 45 | 46 | CREATE TABLE Clasification( 47 | ISBN VARCHAR(13), 48 | IDTheme NUMBER, 49 | 50 | CONSTRAINT CLA_PK PRIMARY KEY(ISBN, IDTheme), 51 | CONSTRAINT CLA_FK_ISBN FOREIGN KEY(ISBN) REFERENCES Publication on delete CASCADE, 52 | CONSTRAINT CLA_FK_Theme FOREIGN KEY(IDTheme) REFERENCES Theme 53 | ); 54 | 55 | /* 56 | * Library System 57 | */ 58 | 59 | CREATE TABLE Book( 60 | ISBN VARCHAR(13), 61 | edition NUMBER(1), 62 | ed_date DATE, 63 | 64 | CONSTRAINT boo_PK PRIMARY KEY(ISBN), 65 | CONSTRAINT boo_FK FOREIGN KEY(ISBN) REFERENCES Publication 66 | ); 67 | 68 | CREATE TABLE Biblioteca( 69 | potal_Code NUMBER(5), 70 | 71 | CONSTRAINT bib_PK PRIMARY KEY(potal_Code) 72 | ); 73 | 74 | CREATE TABLE Journal ( 75 | ISBN VARCHAR(13), 76 | Frecuency VARCHAR(10), 77 | 78 | CONSTRAINT jou_pk PRIMARY KEY(ISBN), 79 | CONSTRAINT jou_fk FOREIGN KEY(ISBN) REFERENCES Publication ON DELETE cascade 80 | ); 81 | 82 | CREATE TABLE Subscription( 83 | ISBN VARCHAR(13), 84 | PC NUMBER(5), 85 | Sub_Date DATE, 86 | 87 | CONSTRAINT sub_pk_isbn PRIMARY KEY(ISBN, PC), 88 | CONSTRAINT sub_fk_isbn FOREIGN KEY(ISBN) REFERENCES Journal ON DELETE cascade, 89 | CONSTRAINT sub_fk_pc FOREIGN KEY(PC) REFERENCES Biblioteca 90 | ); 91 | 92 | CREATE TABLE Member ( 93 | NMember NUMBER, 94 | name VARCHAR(20), 95 | email VARCHAR(25), 96 | Postal_Code NUMBER(5), 97 | 98 | CONSTRAINT mem_pk_nm PRIMARY KEY(NMember), 99 | CONSTRAINT mem_fk_pc FOREIGN KEY(Postal_Code) REFERENCES Biblioteca ON DELETE SET NULL 100 | ); 101 | 102 | CREATE TABLE JournalCopy( 103 | ISBN VARCHAR(13), 104 | PostalCode NUMBER(5), 105 | Num NUMBER(3), 106 | NMember NUMBER NULL, 107 | 108 | CONSTRAINT jou_pk_ISBNPcNum PRIMARY KEY(ISBN, PostalCode, Num), 109 | CONSTRAINT jou_fk_ISBNPc FOREIGN KEY(ISBN, PostalCode) REFERENCES Subscription, 110 | CONSTRAINT jou_fk_NMember FOREIGN KEY(NMember) REFERENCES Member ON DELETE SET NULL 111 | ); 112 | 113 | CREATE TABLE BookCopy( 114 | ISBN VARCHAR(13), 115 | PC NUMBER(5), 116 | Num NUMBER(3), 117 | Adq_Date DATE, 118 | NMember NUMBER NOT NULL, 119 | BorrowDate DATE NOT NULL, 120 | 121 | CONSTRAINT bookCopy_pk_ISBNPc PRIMARY KEY(ISBN, PC), 122 | CONSTRAINT bookCopy_fk_NMember FOREIGN KEY(NMember) REFERENCES Member 123 | ); 124 | -------------------------------------------------------------------------------- /3_Triggers:Procedures/4_ScriptExercises PLSQL.sql: -------------------------------------------------------------------------------- 1 | drop table courses cascade constraints; 2 | drop table inscriptions cascade constraints; 3 | drop table fees cascade constraints; 4 | 5 | create sequence coursesC MINVALUE 1 START WITH 1 6 | INCREMENT BY 1 NOCACHE; 7 | 8 | create table fees ( 9 | levelF varchar(20) DEFAULT 'Beginner' NOT NULL 10 | CONSTRAINT levelF_CK CHECK (levelF IN ('Beginner','Intermediate', 'Advanced')), 11 | typeF varchar(10) DEFAULT 'Regular' NOT NULL 12 | CONSTRAINT Tip_CK CHECK (typeF IN ('Regular','Intensive', 'Private')), 13 | price NUMBER(6,2) DEFAULT 0, 14 | primary key (levelF,typeF)); 15 | 16 | create table courses ( 17 | code char(8) PRIMARY KEY, 18 | name varchar(50) NOT NULL, 19 | levelF varchar(20) NOT NULL, 20 | typeF varchar(10) NOT NULL, 21 | hours NUMBER(3) NOT NULL, 22 | quota NUMBER(3) DEFAULT 12, 23 | foreign key (levelF,typeF) REFERENCES fees); 24 | 25 | create table inscriptions ( 26 | code char(8) NOT NULL, 27 | id_student varchar(10) NOT NULL, 28 | price NUMBER(6,2) DEFAULT 0, 29 | old_student NUMBER(1) DEFAULT 0 30 | CONSTRAINT student_CK CHECK (old_student IN (0,1)), 31 | primary key(code,id_student), 32 | foreign key (code) references courses); 33 | 34 | insert into fees values('Beginner', 'Regular', 675); 35 | insert into fees values('Beginner', 'Intensive', 460); 36 | insert into fees values('Beginner', 'Private', 50); 37 | insert into fees values('Intermediate', 'Intensive', 500); 38 | insert into fees values('Intermediate', 'Regular', 800); 39 | insert into fees values('Intermediate', 'Private', 60); 40 | insert into fees values('Advanced', 'Intensive', 750); 41 | insert into fees values('Advanced', 'Regular', 1000); 42 | insert into fees values('Advanced', 'Private', 90); 43 | 44 | // 45 | create or replace 46 | procedure "LOADEVENTS" is 47 | 48 | begin 49 | 50 | delete from courses; 51 | 52 | FOR curso_ingles in 1..5 LOOP 53 | 54 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Beginner', 'Regular', 10+ (2*coursesC.CURRVAL)); 55 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Beginner', 'Intensive', 10+ (2*coursesC.CURRVAL)); 56 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Beginner', 'Private', 10+ (2*coursesC.CURRVAL)); 57 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Intermediate', 'Regular', 10+ (2*coursesC.CURRVAL)); 58 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Intermediate', 'Intensive', 10+ (2*coursesC.CURRVAL)); 59 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Intermediate', 'Private', 10+ (2*coursesC.CURRVAL)); 60 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Advanced', 'Regular', 10+ (2*coursesC.CURRVAL)); 61 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Advanced', 'Intensive', 10+ (2*coursesC.CURRVAL)); 62 | insert into courses (code, name, levelF, typeF, hours) values('C'||coursesC.NEXTVAL,'Chinese course '||coursesC.CURRVAL,'Advanced', 'Private', 10+ (2*coursesC.CURRVAL)); 63 | 64 | END LOOP; 65 | END; 66 | 67 | // 68 | create or replace 69 | FUNCTION isGreaterQuote(p_code CHAR) 70 | RETURN BOOLEAN 71 | IS 72 | 73 | /* Declarations */ 74 | v_quota number(3); 75 | v_enrolled number(3); 76 | v_first boolean:=true; 77 | v_second boolean:=true; 78 | 79 | BEGIN 80 | 81 | /* Take course quota by parameter */ 82 | SELECT QUOTA into v_quota from Courses 83 | WHERE Courses.Code=p_code; 84 | v_first:=false; /* Esto se ha ejecutado sin problemas*/ 85 | 86 | /* Select count number of incriptions with code of the parameter */ 87 | SELECT COUNT(Code) into v_enrolled 88 | FROM Inscriptions 89 | WHERE Inscriptions.Code=p_code; 90 | v_second:=false; /* Esto se ha ejecutado sin problemas*/ 91 | 92 | if (v_enrolled > v_quota) then 93 | return true; 94 | else 95 | return false; 96 | end if; 97 | 98 | EXCEPTION 99 | WHEN NO_DATA_FOUND THEN 100 | if (v_first=true) then 101 | DBMS_OUTPUT.PUT_LINE('Excepcion en la primera consulta... No hemos encontrado cursos con ese código'); 102 | return false; 103 | end if; 104 | if (v_second=true) then 105 | DBMS_OUTPUT.PUT_LINE('Excepcion en la SEGUNDA consulta... No hemos encontrado estudiantes enrolled en ese curso'); 106 | DBMS_OUTPUT.PUT_LINE('Por lo tanto. Todo esta bien :-)'); 107 | return true; 108 | end if; 109 | /*WHEN TOO_MANY_ROWS THEN 110 | DBMS_OUTPUT.PUT_LINE ('Several organizations found'); 111 | */ 112 | 113 | END; 114 | 115 | 116 | /* 117 | b. Write a stored procedure to enroll a student in a given course. 118 | First, you must check that the quota has not been exceeded (invoke the function previously designed); 119 | If the student cannot be enrolled, show a message that indicates it. 120 | The procedure will receive 3 parameters: course code, student id and a boolean that indicates if 121 | the student was enrolled previously in other course. In the case of regular and intensive courses 122 | the total price of the course will be the one stored in the table Fees. The price associated with 123 | the private courses is the price of one hour. In order to calculate the final price, you have to 124 | multiply it by the number of hours of each course. All the students that were enrolled previously 125 | in a course will obtain a 5% discount. 126 | */ 127 | 128 | // 129 | CREATE OR REPLACE PROCEDURE EnrollStudent 130 | (p_code CHAR, p_IDStudent VARCHAR, p_oldStudent BOOLEAN) 131 | IS 132 | 133 | v_enrolled number:=0; 134 | v_duplicated boolean:=true; 135 | v_availableInscriptions boolean:=false; 136 | 137 | v_total number(3); -- total price for a course 138 | v_type varchar(20); 139 | v_price number(3); 140 | v_hours number(3); 141 | 142 | BEGIN 143 | 144 | -- Check if student has been alreadfy in the courase / Duplicate key (student enrolled previosly?): print and returns 145 | -- NVL= si nulo pones cero en v_enrolled 146 | 147 | SELECT NVL(COUNT(ID_STUDENT),0) into v_enrolled 148 | FROM INSCRIPTIONS 149 | WHERE Inscriptions.Code = p_code and Inscriptions.ID_Student=p_IDStudent; 150 | 151 | if (v_enrolled=1) then 152 | DBMS_OUTPUT.PUT_LINE('This student has been already enrolled'); 153 | else 154 | if(isGreaterQuote(p_code)) then 155 | Select TypeF, price, hours into v_type, v_price,v_hours 156 | FROM Courses natural join fees 157 | WHERE Courses.code=p_code; 158 | 159 | -- Calculate price 160 | 161 | if (v_type='Private') then 162 | v_total:=v_price*v_hours; -- Private courses are hours by the price. 163 | else 164 | v_total:=v_price; 165 | end if; 166 | 167 | if (p_oldStudent=true) then 168 | v_total:=v_total*0.95) -- Apply disccount: 5% if p_oldStudent 169 | end if; 170 | 171 | 172 | -- TODO 173 | -- INSERT INTO TABLE 174 | 175 | 176 | else 177 | -- Show error: quota is exceded.. 178 | -- Quota limite for this course?: print and return 179 | end if; 180 | end if; 181 | 182 | EXCEPTION 183 | WHEN NO_DATA_FOUND THEN 184 | if (v_duplicated=true) then 185 | DBMS_OUTPUT.PUT_LINE('This student has been already enrolled'); 186 | return false; 187 | end if; 188 | 189 | END; 190 | 191 | 192 | 193 | 194 | -------------------------------------------------------------------------------- /2_SQL_Queries/Tables/FlyWithOther.sql: -------------------------------------------------------------------------------- 1 | drop table flight cascade constraints; 2 | drop table aircraft cascade constraints; 3 | drop table employee cascade constraints; 4 | drop table certificate cascade constraints; 5 | 6 | create table flight( 7 | flno number(4,0) primary key, 8 | origin varchar2(20), 9 | destination varchar2(20), 10 | distance number(6,0), 11 | departure_date date, 12 | arrival_date date, 13 | price number(7,2)); 14 | 15 | create table aircraft( 16 | aid number(9,0) primary key, 17 | name varchar2(30), 18 | distance number(6,0)); 19 | 20 | create table employee( 21 | eid number(9,0) primary key, 22 | name varchar2(30), 23 | salary number(10,2)); 24 | 25 | create table certificate( 26 | eid number(9,0), 27 | aid number(9,0), 28 | primary key(eid,aid), 29 | foreign key(eid) references employee, 30 | foreign key(aid) references aircraft); 31 | 32 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (99.0,'Los Angeles','Washington D.C.',2308.0,to_date('04/12/2005 09:30', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 09:40', 'dd/mm/yyyy 33 | HH24:MI'),235.98); 34 | 35 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (13.0,'Los Angeles','Chicago',1749.0,to_date('04/12/2005 08:45', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 08:45', 'dd/mm/yyyy 36 | HH24:MI'),220.98); 37 | 38 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (346.0,'Los Angeles','Dallas',1251.0,to_date('04/12/2005 11:50', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 07:05', 'dd/mm/yyyy 39 | HH24:MI'),225-43); 40 | 41 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (387.0,'Los Angeles','Boston',2606.0,to_date('04/12/2005 07:03', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 05:03', 'dd/mm/yyyy 42 | HH24:MI'),261.56); 43 | 44 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (7.0,'Los Angeles','Sydney',7487.0,to_date('04/12/2005 05:30', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 11:10', 'dd/mm/yyyy 45 | HH24:MI'),278.56); 46 | 47 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (2.0,'Los Angeles','Tokyo',5478.0,to_date('04/12/2005 06:30', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 03:55', 'dd/mm/yyyy 48 | HH24:MI'),780.99); 49 | 50 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (33.0,'Los Angeles','Honolulu',2551.0,to_date('04/12/2005 09:15', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 11:15', 'dd/mm/yyyy 51 | HH24:MI'),375.23); 52 | 53 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (34.0,'Los Angeles','Honolulu',2551.0,to_date('04/12/2005 12:45', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 03:18', 'dd/mm/yyyy 54 | HH24:MI'),425.98); 55 | 56 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (76.0,'Chicago','Los Angeles',1749.0,to_date('04/12/2005 08:32', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 10:03', 'dd/mm/yyyy 57 | HH24:MI'),220.98); 58 | 59 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (68.0,'Chicago','New York',802.0,to_date('04/12/2005 09:00', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 12:02', 'dd/mm/yyyy 60 | HH24:MI'),202.45); 61 | 62 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (7789.0,'Madison','Detroit',319.0,to_date('04/12/2005 06:15', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 08:19', 'dd/mm/yyyy 63 | HH24:MI'),120.33); 64 | 65 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (701.0,'Detroit','New York',470.0,to_date('04/12/2005 08:55', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 10:26', 'dd/mm/yyyy 66 | HH24:MI'),180.56); 67 | 68 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (702.0,'Madison','New York',789.0,to_date('04/12/2005 07:05', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 10:12', 'dd/mm/yyyy 69 | HH24:MI'),202.34); 70 | 71 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (4884.0,'Madison','Chicago',84.0,to_date('04/12/2005 10:12', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 11:02', 'dd/mm/yyyy 72 | HH24:MI'),112.45); 73 | 74 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (2223.0,'Madison','Pittsburgh',517.0,to_date('04/12/2005 08:02', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 10:01', 'dd/mm/yyyy 75 | HH24:MI'),189.98); 76 | 77 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (5694.0,'Madison','Minneapolis',247.0,to_date('04/12/2005 08:32', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 09:33', 'dd/mm/yyyy 78 | HH24:MI'),120.11); 79 | 80 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (304.0,'Minneapolis','New York',991.0,to_date('04/12/2005 10:00', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 01:39', 'dd/mm/yyyy 81 | HH24:MI'),101.56); 82 | 83 | INSERT INTO flight (FLNO, origin, destination, distance, departure_date, arrival_date, price) VALUES (149.0,'Pittsburgh','New York',303.0,to_date('04/12/2005 09:42', 'dd/mm/yyyy HH24:MI'),to_date('04/12/2005 12:09', 'dd/mm/yyyy 84 | HH24:MI'),1165.00); 85 | 86 | Insert into aircraft (AID,name,distance) values ('1','Boeing 747-400','8430'); 87 | Insert into aircraft (AID,name,distance) values ('2','Boeing 737-800','3383'); 88 | Insert into aircraft (AID,name,distance) values ('3','Airbus A340-300','7120'); 89 | Insert into aircraft (AID,name,distance) values ('4','British Aerospace Jetstream 41','1502'); 90 | Insert into aircraft (AID,name,distance) values ('5','Embraer ERJ-145','1530'); 91 | Insert into aircraft (AID,name,distance) values ('6','SAAB 340','2128'); 92 | Insert into aircraft (AID,name,distance) values ('7','Piper Archer III','520'); 93 | Insert into aircraft (AID,name,distance) values ('8','Tupolev 154','4103'); 94 | Insert into aircraft (AID,name,distance) values ('16','Schwitzer 2-33','30'); 95 | Insert into aircraft (AID,name,distance) values ('9','Lockheed L1011','6900'); 96 | Insert into aircraft (AID,name,distance) values ('10','Boeing 757-300','4010'); 97 | Insert into aircraft (AID,name,distance) values ('11','Boeing 777-300','6441'); 98 | Insert into aircraft (AID,name,distance) values ('12','Boeing 767-400ER','6475'); 99 | Insert into aircraft (AID,name,distance) values ('13','Airbus A320','2605'); 100 | Insert into aircraft (AID,name,distance) values ('14','Airbus A319','1805'); 101 | Insert into aircraft (AID,name,distance) values ('15','Boeing 727','1504'); 102 | 103 | 104 | Insert into employee (EID,name,salary) values ('242518965','James Smith','120433'); 105 | Insert into employee (EID,name,salary) values ('141582651','Mary Johnson','178345'); 106 | Insert into employee (EID,name,salary) values ('11564812','John Williams','153972'); 107 | Insert into employee (EID,name,salary) values ('567354612','Lisa Walker','256481'); 108 | Insert into employee (EID,name,salary) values ('552455318','Larry West','101745'); 109 | Insert into employee (EID,name,salary) values ('550156548','Karen Scott','205187'); 110 | Insert into employee (EID,name,salary) values ('390487451','Lawrence Sperry','212156'); 111 | Insert into employee (EID,name,salary) values ('274878974','Michael Miller','99890'); 112 | Insert into employee (EID,name,salary) values ('254099823','Patricia Jones','24450'); 113 | Insert into employee (EID,name,salary) values ('356187925','Robert Brown','44740'); 114 | Insert into employee (EID,name,salary) values ('355548984','Angela Martinez','212156'); 115 | Insert into employee (EID,name,salary) values ('310454876','Joseph Thompson','212156'); 116 | Insert into employee (EID,name,salary) values ('489456522','Linda Davis','27984'); 117 | Insert into employee (EID,name,salary) values ('489221823','Richard Jackson','23980'); 118 | Insert into employee (EID,name,salary) values ('548977562','William Ward','84476'); 119 | Insert into employee (EID,name,salary) values ('310454877','Chad Stewart','33546'); 120 | Insert into employee (EID,name,salary) values ('142519864','Betty Adams','227489'); 121 | Insert into employee (EID,name,salary) values ('269734834','George Wright','289950'); 122 | Insert into employee (EID,name,salary) values ('287321212','Michael Miller','48090'); 123 | Insert into employee (EID,name,salary) values ('552455348','Dorthy Lewis','152013'); 124 | Insert into employee (EID,name,salary) values ('248965255','Barbara Wilson','43723'); 125 | Insert into employee (EID,name,salary) values ('159542516','William Moore','48250'); 126 | Insert into employee (EID,name,salary) values ('348121549','Haywood Kelly','32899'); 127 | Insert into employee (EID,name,salary) values ('90873519','Elizabeth Taylor','32021'); 128 | Insert into employee (EID,name,salary) values ('486512566','David Anderson','43001'); 129 | Insert into employee (EID,name,salary) values ('619023588','Jennifer Thomas','54921'); 130 | Insert into employee (EID,name,salary) values ('15645489','Donald King','18050'); 131 | Insert into employee (EID,name,salary) values ('556784565','Mark Young','205187'); 132 | Insert into employee (EID,name,salary) values ('573284895','Eric Cooper','114323'); 133 | Insert into employee (EID,name,salary) values ('574489456','William Jones','105743'); 134 | Insert into employee (EID,name,salary) values ('574489457','Milo Brooks','20'); 135 | 136 | 137 | Insert into certificate (EID,AID) values ('11564812','2'); 138 | Insert into certificate (EID,AID) values ('11564812','10'); 139 | Insert into certificate (EID,AID) values ('90873519','6'); 140 | Insert into certificate (EID,AID) values ('141582651','2'); 141 | Insert into certificate (EID,AID) values ('141582651','10'); 142 | Insert into certificate (EID,AID) values ('141582651','12'); 143 | Insert into certificate (EID,AID) values ('142519864','1'); 144 | Insert into certificate (EID,AID) values ('142519864','2'); 145 | Insert into certificate (EID,AID) values ('142519864','3'); 146 | Insert into certificate (EID,AID) values ('142519864','7'); 147 | Insert into certificate (EID,AID) values ('142519864','10'); 148 | Insert into certificate (EID,AID) values ('142519864','11'); 149 | Insert into certificate (EID,AID) values ('142519864','12'); 150 | Insert into certificate (EID,AID) values ('142519864','13'); 151 | Insert into certificate (EID,AID) values ('159542516','5'); 152 | Insert into certificate (EID,AID) values ('159542516','7'); 153 | Insert into certificate (EID,AID) values ('242518965','2'); 154 | Insert into certificate (EID,AID) values ('242518965','10'); 155 | Insert into certificate (EID,AID) values ('269734834','1'); 156 | Insert into certificate (EID,AID) values ('269734834','2'); 157 | Insert into certificate (EID,AID) values ('269734834','3'); 158 | Insert into certificate (EID,AID) values ('269734834','4'); 159 | Insert into certificate (EID,AID) values ('269734834','5'); 160 | Insert into certificate (EID,AID) values ('269734834','6'); 161 | Insert into certificate (EID,AID) values ('269734834','7'); 162 | Insert into certificate (EID,AID) values ('269734834','8'); 163 | Insert into certificate (EID,AID) values ('269734834','9'); 164 | Insert into certificate (EID,AID) values ('269734834','10'); 165 | Insert into certificate (EID,AID) values ('269734834','11'); 166 | Insert into certificate (EID,AID) values ('269734834','12'); 167 | Insert into certificate (EID,AID) values ('269734834','13'); 168 | Insert into certificate (EID,AID) values ('269734834','14'); 169 | Insert into certificate (EID,AID) values ('269734834','15'); 170 | Insert into certificate (EID,AID) values ('274878974','10'); 171 | Insert into certificate (EID,AID) values ('274878974','12'); 172 | Insert into certificate (EID,AID) values ('310454876','8'); 173 | Insert into certificate (EID,AID) values ('310454876','9'); 174 | Insert into certificate (EID,AID) values ('355548984','8'); 175 | Insert into certificate (EID,AID) values ('355548984','9'); 176 | Insert into certificate (EID,AID) values ('356187925','6'); 177 | Insert into certificate (EID,AID) values ('390487451','3'); 178 | Insert into certificate (EID,AID) values ('390487451','13'); 179 | Insert into certificate (EID,AID) values ('390487451','14'); 180 | Insert into certificate (EID,AID) values ('548977562','7'); 181 | Insert into certificate (EID,AID) values ('550156548','1'); 182 | Insert into certificate (EID,AID) values ('550156548','12'); 183 | Insert into certificate (EID,AID) values ('552455318','2'); 184 | Insert into certificate (EID,AID) values ('552455318','7'); 185 | Insert into certificate (EID,AID) values ('552455318','14'); 186 | Insert into certificate (EID,AID) values ('556784565','2'); 187 | Insert into certificate (EID,AID) values ('556784565','3'); 188 | Insert into certificate (EID,AID) values ('556784565','5'); 189 | Insert into certificate (EID,AID) values ('567354612','1'); 190 | Insert into certificate (EID,AID) values ('567354612','2'); 191 | Insert into certificate (EID,AID) values ('567354612','3'); 192 | Insert into certificate (EID,AID) values ('567354612','4'); 193 | Insert into certificate (EID,AID) values ('567354612','5'); 194 | Insert into certificate (EID,AID) values ('567354612','7'); 195 | Insert into certificate (EID,AID) values ('567354612','9'); 196 | Insert into certificate (EID,AID) values ('567354612','10'); 197 | Insert into certificate (EID,AID) values ('567354612','11'); 198 | Insert into certificate (EID,AID) values ('567354612','12'); 199 | Insert into certificate (EID,AID) values ('567354612','15'); 200 | Insert into certificate (EID,AID) values ('573284895','3'); 201 | Insert into certificate (EID,AID) values ('573284895','4'); 202 | Insert into certificate (EID,AID) values ('573284895','5'); 203 | Insert into certificate (EID,AID) values ('574489456','6'); 204 | Insert into certificate (EID,AID) values ('574489456','8'); 205 | Insert into certificate (EID,AID) values ('574489457','7'); 206 | --------------------------------------------------------------------------------