
USE PerancanganBD

/******************************************************************************/
/* EMPLOYEES                                                                  */
/******************************************************************************/

CREATE TABLE EMPLOYEES
  (
    EMPLOYEE_ID  NUMERIC(6,0),
    FIRST_NAME   NVARCHAR(20),
    LAST_NAME    NVARCHAR(25) NOT NULL,
    EMAIL        NVARCHAR(25) NOT NULL,
    PHONE_NUMBER NVARCHAR(20),
    HIRE_DATE DATETIME NOT NULL,
    JOB_ID         NVARCHAR(10) NOT NULL,
    SALARY         NUMERIC(8,2),
    COMMISSION_PCT NUMERIC(2,2),
    MANAGER_ID     NUMERIC(6,0),
    DEPARTMENT_ID  NUMERIC(4,0),
    CONSTRAINT EMP_EMP_ID_PK PRIMARY KEY (EMPLOYEE_ID)
  )

ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_SALARY_MIN CHECK (SALARY > 0)
ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_EMAIL_UK UNIQUE (EMAIL)
ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_MANAGER_FK FOREIGN KEY (MANAGER_ID) REFERENCES EMPLOYEES (EMPLOYEE_ID)
ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_JOB_FK FOREIGN KEY (JOB_ID) REFERENCES JOBS (JOB_ID)
ALTER TABLE EMPLOYEES ADD CONSTRAINT EMP_DEPT_FK FOREIGN KEY (DEPARTMENT_ID) REFERENCES DEPARTMENTS (DEPARTMENT_ID)

INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (198,'Donald','OConnell','DOCONNEL','650.507.9833',CONVERT (DATETIME, '06-21-1999'), 'SH_CLERK', 2600, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (199,'Douglas','Grant','DGRANT','650.507.9844',CONVERT (DATETIME, '01-13-2000'), 'SH_CLERK', 2600, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (200,'Jennifer','Whalen','JWHALEN','515.123.4444',CONVERT (DATETIME, '09-17-1987'), 'AD_ASST', 4400, NULL, 101, 10);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (201,'Michael','Hartstein','MHARTSTE','515.123.5555',CONVERT (DATETIME, '02-17-1996'), 'MK_MAN', 13000, NULL, 100, 20);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (202,'Pat','Fay','PFAY','603.123.6666',CONVERT (DATETIME, '08-17-1997'), 'MK_REP', 6000, NULL, 201, 20);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (203,'Susan','Mavris','SMAVRIS','515.123.7777',CONVERT (DATETIME, '06-07-1994'), 'HR_REP', 6500, NULL, 101, 40);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (204,'Hermann','Baer','HBAER','515.123.8888',CONVERT (DATETIME, '06-07-1994'), 'PR_REP', 10000, NULL, 101, 70);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (205,'Shelley','Higgins','SHIGGINS','515.123.8080',CONVERT (DATETIME, '06-07-1994'), 'AC_MGR', 12000, NULL, 101, 110);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (206,'William','Gietz','WGIETZ','515.123.8181',CONVERT (DATETIME, '06-07-1994'), 'AC_ACCOUNT', 8300, NULL, 205, 110);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (100,'Steven','King','SKING','515.123.4567',CONVERT (DATETIME, '06-17-1987'), 'AD_PRES', 24000, NULL, NULL, 90);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (101,'Neena','Kochhar','NKOCHHAR','515.123.4568',CONVERT (DATETIME, '09-21-1989'), 'AD_VP', 17000, NULL, 100, 90);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (102,'Lex','De Haan','LDEHAAN','515.123.4569',CONVERT (DATETIME, '01-13-1993'), 'AD_VP', 17000, NULL, 100, 90);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (103,'Alexander','Hunold','AHUNOLD','590.423.4567',CONVERT (DATETIME, '01-03-1990'), 'IT_PROG', 9000, NULL, 102, 60);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (104,'Bruce','Ernst','BERNST','590.423.4568',CONVERT (DATETIME, '05-21-1991'), 'IT_PROG', 6000, NULL, 103, 60);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (105,'David','Austin','DAUSTIN','590.423.4569',CONVERT (DATETIME, '06-25-1997'), 'IT_PROG', 4800, NULL, 103, 60);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (106,'Valli','Pataballa','VPATABAL','590.423.4560',CONVERT (DATETIME, '02-05-1998'), 'IT_PROG', 4800, NULL, 103, 60);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (107,'Diana','Lorentz','DLORENTZ','590.423.5567',CONVERT (DATETIME, '02-07-1999'), 'IT_PROG', 4200, NULL, 103, 60);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (108,'Nancy','Greenberg','NGREENBE','515.124.4569',CONVERT (DATETIME, '08-17-1994'), 'FI_MGR', 12000, NULL, 101, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (109,'Daniel','Faviet','DFAVIET','515.124.4169',CONVERT (DATETIME, '08-16-1994'), 'FI_ACCOUNT', 9000, NULL, 108, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (110,'John','Chen','JCHEN','515.124.4269',CONVERT (DATETIME, '09-28-1997'), 'FI_ACCOUNT', 8200, NULL, 108, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (111,'Ismael','Sciarra','ISCIARRA','515.124.4369',CONVERT (DATETIME, '09-30-1997'), 'FI_ACCOUNT', 7700, NULL, 108, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (112,'Jose Manuel','Urman','JMURMAN','515.124.4469',CONVERT (DATETIME, '03-07-1998'), 'FI_ACCOUNT', 7800, NULL, 108, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (113,'Luis','Popp','LPOPP','515.124.4567',CONVERT (DATETIME, '12-07-1999'), 'FI_ACCOUNT', 6900, NULL, 108, 100);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (114,'Den','Raphaely','DRAPHEAL','515.127.4561',CONVERT (DATETIME, '12-07-1994'), 'PU_MAN', 11000, NULL, 100, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (115,'Alexander','Khoo','AKHOO','515.127.4562',CONVERT (DATETIME, '05-18-1995'), 'PU_CLERK', 3100, NULL, 114, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (116,'Shelli','Baida','SBAIDA','515.127.4563',CONVERT (DATETIME, '12-24-1997'), 'PU_CLERK', 2900, NULL, 114, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (117,'Sigal','Tobias','STOBIAS','515.127.4564',CONVERT (DATETIME, '07-24-1997'), 'PU_CLERK', 2800, NULL, 114, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (118,'Guy','Himuro','GHIMURO','515.127.4565',CONVERT (DATETIME, '11-15-1998'), 'PU_CLERK', 2600, NULL, 114, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (119,'Karen','Colmenares','KCOLMENA','515.127.4566',CONVERT (DATETIME, '08-10-1999'), 'PU_CLERK', 2500, NULL, 114, 30);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (120,'Matthew','Weiss','MWEISS','650.123.1234',CONVERT (DATETIME, '07-18-1996'), 'ST_MAN', 8000, NULL, 100, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (121,'Adam','Fripp','AFRIPP','650.123.2234',CONVERT (DATETIME, '04-10-1997'), 'ST_MAN', 8200, NULL, 100, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (122,'Payam','Kaufling','PKAUFLIN','650.123.3234',CONVERT (DATETIME, '05-01-1995'), 'ST_MAN', 7900, NULL, 100, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (123,'Shanta','Vollman','SVOLLMAN','650.123.4234',CONVERT (DATETIME, '10-10-1997'), 'ST_MAN', 6500, NULL, 100, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (124,'Kevin','Mourgos','KMOURGOS','650.123.5234',CONVERT (DATETIME, '11-16-1999'), 'ST_MAN', 5800, NULL, 100, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (125,'Julia','Nayer','JNAYER','650.124.1214',CONVERT (DATETIME, '07-16-1997'), 'ST_CLERK', 3200, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (126,'Irene','Mikkilineni','IMIKKILI','650.124.1224',CONVERT (DATETIME, '09-28-1998'), 'ST_CLERK', 2700, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (127,'James','Landry','JLANDRY','650.124.1334',CONVERT (DATETIME, '01-14-1999'), 'ST_CLERK', 2400, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (128,'Steven','Markle','SMARKLE','650.124.1434',CONVERT (DATETIME, '03-08-2000'), 'ST_CLERK', 2200, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (129,'Laura','Bissot','LBISSOT','650.124.5234',CONVERT (DATETIME, '08-20-1997'), 'ST_CLERK', 3300, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (130,'Mozhe','Atkinson','MATKINSO','650.124.6234',CONVERT (DATETIME, '10-30-1997'), 'ST_CLERK', 2800, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (131,'James','Marlow','JAMRLOW','650.124.7234',CONVERT (DATETIME, '02-16-1997'), 'ST_CLERK', 2500, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (132,'TJ','Olson','TJOLSON','650.124.8234',CONVERT (DATETIME, '04-10-1999'), 'ST_CLERK', 2100, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (133,'Jason','Mallin','JMALLIN','650.127.1934',CONVERT (DATETIME, '06-14-1996'), 'ST_CLERK', 3300, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (134,'Michael','Rogers','MROGERS','650.127.1834',CONVERT (DATETIME, '08-26-1998'), 'ST_CLERK', 2900, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (135,'Ki','Gee','KGEE','650.127.1734',CONVERT (DATETIME, '12-12-1999'), 'ST_CLERK', 2400, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (136,'Hazel','Philtanker','HPHILTAN','650.127.1634',CONVERT (DATETIME, '02-06-2000'), 'ST_CLERK', 2200, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (137,'Renske','Ladwig','RLADWIG','650.121.1234',CONVERT (DATETIME, '07-14-1995'), 'ST_CLERK', 3600, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (138,'Stephen','Stiles','SSTILES','650.121.2034',CONVERT (DATETIME, '10-26-1997'), 'ST_CLERK', 3200, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (139,'John','Seo','JSEO','650.121.2019',CONVERT (DATETIME, '02-12-1998'), 'ST_CLERK', 2700, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (140,'Joshua','Patel','JPATEL','650.121.1834',CONVERT (DATETIME, '04-06-1998'), 'ST_CLERK', 2500, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (141,'Trenna','Rajs','TRAJS','650.121.8009',CONVERT (DATETIME, '10-17-1995'), 'ST_CLERK', 3500, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (142,'Curtis','Davies','CDAVIES','650.121.2994',CONVERT (DATETIME, '01-29-1997'), 'ST_CLERK', 3100, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (143,'Randall','Matos','RMATOS','650.121.2874',CONVERT (DATETIME, '03-15-1998'), 'ST_CLERK', 2600, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (144,'Peter','Vargas','PVARGAS','650.121.2004',CONVERT (DATETIME, '07-09-1998'), 'ST_CLERK', 2500, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (145,'John','Russell','JRUSSEL','011.44.1344.429268',CONVERT (DATETIME, '10-01-1996'), 'SA_MAN', 14000, 0.4, 100, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (146,'Karen','Partners','KPARTNER','011.44.1344.467268',CONVERT (DATETIME, '01-05-1997'), 'SA_MAN', 13500, 0.3, 100, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (147,'Alberto','Errazuriz','AERRAZUR','011.44.1344.429278',CONVERT (DATETIME, '03-10-1997'), 'SA_MAN', 12000, 0.3, 100, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (148,'Gerald','Cambrault','GCAMBRAU','011.44.1344.619268',CONVERT (DATETIME, '10-15-1999'), 'SA_MAN', 11000, 0.3, 100, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (149,'Eleni','Zlotkey','EZLOTKEY','011.44.1344.429018',CONVERT (DATETIME, '01-29-2000'), 'SA_MAN', 10500, 0.2, 100, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (150,'Peter','Tucker','PTUCKER','011.44.1344.129268',CONVERT (DATETIME, '01-30-1997'), 'SA_REP', 10000, 0.3, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (151,'David','Bernstein','DBERNSTE','011.44.1344.345268',CONVERT (DATETIME, '03-24-1997'), 'SA_REP', 9500, 0.25, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (152,'Peter','Hall','PHALL','011.44.1344.478968',CONVERT (DATETIME, '08-20-1997'), 'SA_REP', 9000, 0.25, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (153,'Christopher','Olsen','COLSEN','011.44.1344.498718',CONVERT (DATETIME, '03-30-1998'), 'SA_REP', 8000, 0.2, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (154,'Nanette','Cambrault','NCAMBRAU','011.44.1344.987668',CONVERT (DATETIME, '12-09-1998'), 'SA_REP', 7500, 0.2, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (155,'Oliver','Tuvault','OTUVAULT','011.44.1344.486508',CONVERT (DATETIME, '11-23-1999'), 'SA_REP', 7000, 0.15, 145, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (156,'Janette','King','JKING','011.44.1345.429268',CONVERT (DATETIME, '01-30-1996'), 'SA_REP', 10000, 0.35, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (157,'Patrick','Sully','PSULLY','011.44.1345.929268',CONVERT (DATETIME, '03-04-1996'), 'SA_REP', 9500, 0.35, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (158,'Allan','McEwen','AMCEWEN','011.44.1345.829268',CONVERT (DATETIME, '08-01-1996'), 'SA_REP', 9000, 0.35, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (159,'Lindsey','Smith','LSMITH','011.44.1345.729268',CONVERT (DATETIME, '03-10-1997'), 'SA_REP', 8000, 0.3, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (160,'Louise','Doran','LDORAN','011.44.1345.629268',CONVERT (DATETIME, '12-15-1997'), 'SA_REP', 7500, 0.3, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (161,'Sarath','Sewall','SSEWALL','011.44.1345.529268',CONVERT (DATETIME, '11-03-1998'), 'SA_REP', 7000, 0.25, 146, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (162,'Clara','Vishney','CVISHNEY','011.44.1346.129268',CONVERT (DATETIME, '11-11-1997'), 'SA_REP', 10500, 0.25, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (163,'Danielle','Greene','DGREENE','011.44.1346.229268',CONVERT (DATETIME, '03-19-1999'), 'SA_REP', 9500, 0.15, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (164,'Mattea','Marvins','MMARVINS','011.44.1346.329268',CONVERT (DATETIME, '01-24-2000'), 'SA_REP', 7200, 0.1, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (165,'David','Lee','DLEE','011.44.1346.529268',CONVERT (DATETIME, '02-23-2000'), 'SA_REP', 6800, 0.1, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (166,'Sundar','Ande','SANDE','011.44.1346.629268',CONVERT (DATETIME, '03-24-2000'), 'SA_REP', 6400, 0.1, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (167,'Amit','Banda','ABANDA','011.44.1346.729268',CONVERT (DATETIME, '04-21-2000'), 'SA_REP', 6200, 0.1, 147, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (168,'Lisa','Ozer','LOZER','011.44.1343.929268',CONVERT (DATETIME, '03-11-1997'), 'SA_REP', 11500, 0.25, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (169,'Harrison','Bloom','HBLOOM','011.44.1343.829268',CONVERT (DATETIME, '03-23-1998'), 'SA_REP', 10000, 0.2, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (170,'Tayler','Fox','TFOX','011.44.1343.729268',CONVERT (DATETIME, '01-24-1998'), 'SA_REP', 9600, 0.2, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (171,'William','Smith','WSMITH','011.44.1343.629268',CONVERT (DATETIME, '02-23-1999'), 'SA_REP', 7400, 0.15, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (172,'Elizabeth','Bates','EBATES','011.44.1343.529268',CONVERT (DATETIME, '03-24-1999'), 'SA_REP', 7300, 0.15, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (173,'Sundita','Kumar','SKUMAR','011.44.1343.329268',CONVERT (DATETIME, '04-21-2000'), 'SA_REP', 6100, 0.1, 148, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (174,'Ellen','Abel','EABEL','011.44.1644.429267',CONVERT (DATETIME, '05-11-1996'), 'SA_REP', 11000, 0.3, 149, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (175,'Alyssa','Hutton','AHUTTON','011.44.1644.429266',CONVERT (DATETIME, '03-19-1997'), 'SA_REP', 8800, 0.25, 149, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (176,'Jonathon','Taylor','JTAYLOR','011.44.1644.429265',CONVERT (DATETIME, '03-24-1998'), 'SA_REP', 8600, 0.2, 149, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (177,'Jack','Livingston','JLIVINGS','011.44.1644.429264',CONVERT (DATETIME, '04-23-1998'), 'SA_REP', 8400, 0.2, 149, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (178,'Kimberely','Grant','KGRANT','011.44.1644.429263',CONVERT (DATETIME, '05-24-1999'), 'SA_REP', 7000, 0.15, 149, NULL);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (179,'Charles','Johnson','CJOHNSON','011.44.1644.429262',CONVERT (DATETIME, '01-04-2000'), 'SA_REP', 6200, 0.1, 149, 80);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (180,'Winston','Taylor','WTAYLOR','650.507.9876',CONVERT (DATETIME, '01-24-1998'), 'SH_CLERK', 3200, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (181,'Jean','Fleaur','JFLEAUR','650.507.9877',CONVERT (DATETIME, '02-23-1998'), 'SH_CLERK', 3100, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (182,'Martha','Sullivan','MSULLIVA','650.507.9878',CONVERT (DATETIME, '06-21-1999'), 'SH_CLERK', 2500, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (183,'Girard','Geoni','GGEONI','650.507.9879',CONVERT (DATETIME, '02-03-2000'), 'SH_CLERK', 2800, NULL, 120, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (184,'Nandita','Sarchand','NSARCHAN','650.509.1876',CONVERT (DATETIME, '01-27-1996'), 'SH_CLERK', 4200, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (185,'Alexis','Bull','ABULL','650.509.2876',CONVERT (DATETIME, '02-20-1997'), 'SH_CLERK', 4100, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (186,'Julia','Dellinger','JDELLING','650.509.3876',CONVERT (DATETIME, '06-24-1998'), 'SH_CLERK', 3400, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (187,'Anthony','Cabrio','ACABRIO','650.509.4876',CONVERT (DATETIME, '02-07-1999'), 'SH_CLERK', 3000, NULL, 121, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (188,'Kelly','Chung','KCHUNG','650.505.1876',CONVERT (DATETIME, '06-14-1997'), 'SH_CLERK', 3800, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (189,'Jennifer','Dilly','JDILLY','650.505.2876',CONVERT (DATETIME, '08-13-1997'), 'SH_CLERK', 3600, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (190,'Timothy','Gates','TGATES','650.505.3876',CONVERT (DATETIME, '07-11-1998'), 'SH_CLERK', 2900, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (191,'Randall','Perkins','RPERKINS','650.505.4876',CONVERT (DATETIME, '12-19-1999'), 'SH_CLERK', 2500, NULL, 122, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (192,'Sarah','Bell','SBELL','650.501.1876',CONVERT (DATETIME, '02-04-1996'), 'SH_CLERK', 4000, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (193,'Britney','Everett','BEVERETT','650.501.2876',CONVERT (DATETIME, '03-03-1997'), 'SH_CLERK', 3900, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (194,'Samuel','McCain','SMCCAIN','650.501.3876',CONVERT (DATETIME, '07-01-1998'), 'SH_CLERK', 3200, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (195,'Vance','Jones','VJONES','650.501.4876',CONVERT (DATETIME, '03-17-1999'), 'SH_CLERK', 2800, NULL, 123, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (196,'Alana','Walsh','AWALSH','650.507.9811',CONVERT (DATETIME, '04-24-1998'), 'SH_CLERK', 3100, NULL, 124, 50);
INSERT INTO EMPLOYEES (EMPLOYEE_ID,FIRST_NAME,LAST_NAME,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID,DEPARTMENT_ID) VALUES (197,'Kevin','Feeney','KFEENEY','650.507.9822',CONVERT (DATETIME, '05-23-1998'), 'SH_CLERK', 3000, NULL, 124, 50);

/******************************************************************************/
/* DEPARTMENTS                                                                */
/******************************************************************************/

CREATE TABLE DEPARTMENTS
  (
    DEPARTMENT_ID   NUMERIC(4,0),
    DEPARTMENT_NAME NVARCHAR(30) NOT NULL,
    MANAGER_ID      NUMERIC(6,0),
    LOCATION_ID     NUMERIC(4,0),
    CONSTRAINT DEPT_ID_PK PRIMARY KEY (DEPARTMENT_ID)
  )

ALTER TABLE DEPARTMENTS ADD CONSTRAINT DEPT_MGR_FK FOREIGN KEY (MANAGER_ID) REFERENCES EMPLOYEES (EMPLOYEE_ID)

ALTER TABLE DEPARTMENTS ADD CONSTRAINT DEPT_LOC_FK FOREIGN KEY (LOCATION_ID) REFERENCES LOCATIONS (LOCATION_ID)

CREATE INDEX DEPT_LOCATION_IX ON DEPARTMENTS (LOCATION_ID)

INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (10,'Administration',200,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (20,'Marketing',201,1800);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (30,'Purchasing',114,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (40,'Human Resources',203,2400);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (50,'Shipping',121,1500);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (60,'IT',103,1400);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (70,'Public Relations',204,2700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (80,'Sales',145,2500);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (90,'Executive',100,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (100,'Finance',108,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (110,'Accounting',205,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (120,'Treasury',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (130,'Corporate Tax',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (140,'Control And Credit',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (150,'Shareholder Services',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (160,'Benefits',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (170,'Manufacturing',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (180,'Construction',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (190,'Contracting',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (200,'Operations',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (210,'IT Support',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (220,'NOC',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (230,'IT Helpdesk',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (240,'Government Sales',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (250,'Retail Sales',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (260,'Recruiting',NULL,1700);
INSERT INTO DEPARTMENTS (DEPARTMENT_ID,DEPARTMENT_NAME,MANAGER_ID,LOCATION_ID) VALUES (270,'Payroll',NULL,1700);

/******************************************************************************/
/* JOBS                                                                       */
/******************************************************************************/

CREATE TABLE JOBS
  (
    JOB_ID     NVARCHAR(10),
    JOB_TITLE  NVARCHAR(35) NOT NULL,
    MIN_SALARY NUMERIC(6,0),
    MAX_SALARY NUMERIC(6,0),
    CONSTRAINT JOB_ID_PK PRIMARY KEY (JOB_ID)
  )

INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('AD_PRES','President',20000,40000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('AD_VP','Administration Vice President',15000,30000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('AD_ASST','Administration Assistant',3000,6000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('FI_MGR','Finance Manager',8200,16000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('FI_ACCOUNT','Accountant',4200,9000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('AC_MGR','Accounting Manager',8200,16000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('AC_ACCOUNT','Public Accountant',4200,9000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('SA_MAN','Sales Manager',10000,20000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('SA_REP','Sales Representative',6000,12000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('PU_MAN','Purchasing Manager',8000,15000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('PU_CLERK','Purchasing Clerk',2500,5500);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('ST_MAN','Stock Manager',5500,8500);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('ST_CLERK','Stock Clerk',2000,5000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('SH_CLERK','Shipping Clerk',2500,5500);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('IT_PROG','Programmer',4000,10000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('MK_MAN','Marketing Manager',9000,15000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('MK_REP','Marketing Representative',4000,9000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('HR_REP','Human Resources Representative',4000,9000);
INSERT INTO JOBS (JOB_ID,JOB_TITLE,MIN_SALARY,MAX_SALARY) VALUES ('PR_REP','Public Relations Representative',4500,10500);

/******************************************************************************/
/* LOCATIONS                                                                  */
/******************************************************************************/

CREATE TABLE LOCATIONS
  (
    LOCATION_ID    NUMERIC(4,0),
    STREET_ADDRESS NVARCHAR(40),
    POSTAL_CODE    NVARCHAR(12),
    CITY           NVARCHAR(30) NOT NULL,
    STATE_PROVINCE NVARCHAR(25),
    COUNTRY_ID     NCHAR(2),
    CONSTRAINT LOC_ID_PK PRIMARY KEY (LOCATION_ID)
  )

ALTER TABLE LOCATIONS ADD CONSTRAINT LOC_C_ID_FK FOREIGN KEY (COUNTRY_ID) REFERENCES COUNTRIES (COUNTRY_ID)

CREATE INDEX LOC_CITY_IX ON LOCATIONS (CITY)

CREATE INDEX LOC_COUNTRY_IX ON LOCATIONS (COUNTRY_ID)

CREATE INDEX LOC_STATE_PROVINCE_IX ON LOCATIONS (STATE_PROVINCE)

INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1000,'1297 Via Cola di Rie','00989','Roma',NULL,'IT');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1100,'93091 Calle della Testa','10934','Venice',NULL,'IT');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1200,'2017 Shinjuku-ku','1689','Tokyo','Tokyo Prefecture','JP');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1300,'9450 Kamiya-cho','6823','Hiroshima',NULL,'JP');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1400,'2014 Jabberwocky Rd','26192','Southlake','Texas','US');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1500,'2011 Interiors Blvd','99236','South San Francisco','California','US');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1600,'2007 Zagora St','50090','South Brunswick','New Jersey','US');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1700,'2004 Charade Rd','98199','Seattle','Washington','US');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1800,'147 Spadina Ave','M5V 2L7','Toronto','Ontario','CA');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (1900,'6092 Boxwood St','YSW 9T2','Whitehorse','Yukon','CA');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2000,'40-5-12 Laogianggen','190518','Beijing',NULL,'CN');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2100,'1298 Vileparle (E)','490231','Bombay','Maharashtra','IN');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2200,'12-98 Victoria Street','2901','Sydney','New South Wales','AU');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2300,'198 Clementi North','540198','Singapore',NULL,'SG');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2400,'8204 Arthur St',NULL,'London',NULL,'UK');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2500,'Magdalen Centre, The Oxford Science Park','OX9 9ZB','Oxford','Oxford','UK');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2600,'9702 Chester Road','09629850293','Stretford','Manchester','UK');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2700,'Schwanthalerstr. 7031','80925','Munich','Bavaria','DE');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2800,'Rua Frei Caneca 1360 ','01307-002','Sao Paulo','Sao Paulo','BR');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (2900,'20 Rue des Corps-Saints','1730','Geneva','Geneve','CH');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (3000,'Murtenstrasse 921','3095','Bern','BE','CH');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (3100,'Pieter Breughelstraat 837','3029SK','Utrecht','Utrecht','NL');
INSERT INTO LOCATIONS (LOCATION_ID,STREET_ADDRESS,POSTAL_CODE,CITY,STATE_PROVINCE,COUNTRY_ID) VALUES (3200,'Mariano Escobedo 9991','11932','Mexico City','Distrito Federal,','MX');

/******************************************************************************/
/* REGIONS                                                                    */
/******************************************************************************/

CREATE TABLE REGIONS
  (
    REGION_ID   NUMERIC NOT NULL,
    REGION_NAME NVARCHAR(25),
    CONSTRAINT REG_ID_PK PRIMARY KEY (REGION_ID)
  )

INSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (1,'Europe');
INSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (2,'Americas');
INSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (3,'Asia');
INSERT INTO REGIONS (REGION_ID,REGION_NAME) VALUES (4,'Middle East and Africa');

/******************************************************************************/
/* COUNTRIES                                                                  */
/******************************************************************************/

CREATE TABLE COUNTRIES
  (
    COUNTRY_ID   NCHAR(2) NOT NULL,
    COUNTRY_NAME NVARCHAR(40),
    REGION_ID    NUMERIC,
    CONSTRAINT COUNTRY_C_ID_PK PRIMARY KEY (COUNTRY_ID)
  )

ALTER TABLE COUNTRIES ADD CONSTRAINT COUNTR_REG_FK FOREIGN KEY (REGION_ID) REFERENCES REGIONS (REGION_ID)

INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('AR','Argentina',2);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('AU','Australia',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('BE','Belgium',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('BR','Brazil',2);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('CA','Canada',2);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('CH','Switzerland',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('CN','China',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('DE','Germany',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('DK','Denmark',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('EG','Egypt',4);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('FR','France',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('HK','HongKong',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('IL','Israel',4);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('IN','India',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('IT','Italy',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('JP','Japan',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('KW','Kuwait',4);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('MX','Mexico',2);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('NG','Nigeria',4);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('NL','Netherlands',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('SG','Singapore',3);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('UK','United Kingdom',1);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('US','United States of America',2);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('ZM','Zambia',4);
INSERT INTO COUNTRIES (COUNTRY_ID,COUNTRY_NAME,REGION_ID) VALUES ('ZW','Zimbabwe',4);

/******************************************************************************/
/* SELECT                                                                     */
/******************************************************************************/

/* INNER JOIN dan OUTER JOIN */
SELECT EMP.FIRST_NAME, EMP.LAST_NAME, EMP.SALARY, MAN.FIRST_NAME + MAN.LAST_NAME MANAGER_NAME, JOB.JOB_TITLE, DEP.DEPARTMENT_NAME, LOC.CITY, COU.COUNTRY_NAME, REG.REGION_NAME
FROM EMPLOYEES EMP
LEFT JOIN EMPLOYEES MAN ON EMP.MANAGER_ID = MAN.EMPLOYEE_ID
JOIN JOBS JOB ON EMP.JOB_ID = JOB.JOB_ID
LEFT JOIN DEPARTMENTS DEP ON EMP.DEPARTMENT_ID = DEP.DEPARTMENT_ID
LEFT JOIN LOCATIONS LOC ON DEP.LOCATION_ID = LOC.LOCATION_ID
LEFT JOIN COUNTRIES COU ON LOC.COUNTRY_ID = COU.COUNTRY_ID
LEFT JOIN REGIONS REG ON COU.REGION_ID = REG.REGION_ID


/* SUB-QUERY pada WHERE clause */
SELECT *
  FROM EMPLOYEES
 WHERE MANAGER_ID = (
SELECT EMPLOYEE_ID
  FROM EMPLOYEES
 WHERE MANAGER_ID IS NULL)

SELECT *
  FROM EMPLOYEES
 WHERE MANAGER_ID IN (
SELECT EMPLOYEE_ID
  FROM EMPLOYEES
 WHERE MANAGER_ID = 100)

/* SELECT dengan SUB-QUERY pada SELECT clause */
SELECT UPP.FIRST_NAME + UPP.LAST_NAME EMPLOYEE_NAME, (
SELECT INN.FIRST_NAME + INN.LAST_NAME
  FROM EMPLOYEES INN
 WHERE INN.EMPLOYEE_ID = UPP.MANAGER_ID) MANAGER_NAME
  FROM EMPLOYEES UPP

/* SELECT dengan SUB-QUERY pada FROM clause, memberikan hasil sama dengan atas */
   SELECT UPP.FIRST_NAME + UPP.LAST_NAME EMPLOYEE_NAME, INN.FIRST_NAME + INN.LAST_NAME MANAGER_NAME
     FROM EMPLOYEES UPP
LEFT JOIN (
   SELECT *
     FROM EMPLOYEES) INN
       ON UPP.MANAGER_ID = INN.EMPLOYEE_ID

/* SELECT dengan JOIN clause, memberikan hasil sama dengan atas */
   SELECT EMP.FIRST_NAME + EMP.LAST_NAME EMPLOYEE_NAME, MAN.FIRST_NAME + MAN.LAST_NAME MANAGER_NAME
     FROM EMPLOYEES EMP
LEFT JOIN EMPLOYEES MAN
       ON EMP.MANAGER_ID = MAN.EMPLOYEE_ID

/******************************************************************************/
/* INDEX                                                                      */
/******************************************************************************/

SELECT *
  FROM LOCATIONS

SELECT *
  FROM LOCATIONS
  WITH (INDEX(LOC_CITY_IX))
 WHERE CITY = 'Seattle'

SELECT *
  FROM DEPARTMENTS dep, EMPLOYEES emp
 WHERE dep.DEPARTMENT_ID = emp.DEPARTMENT_ID
   AND dep.LOCATION_ID = 1700

SELECT *
  FROM EMPLOYEES emp
  WITH (INDEX (EMP_EMP_ID_PK))
  JOIN DEPARTMENTS dep
  WITH (INDEX (DEPT_ID_PK))
    ON dep.DEPARTMENT_ID = emp.DEPARTMENT_ID
   AND dep.LOCATION_ID = 1700

SELECT *
  FROM EMPLOYEES emp
  JOIN DEPARTMENTS dep
  WITH (INDEX (DEPT_LOCATION_IX))
    ON dep.DEPARTMENT_ID = emp.DEPARTMENT_ID
   AND dep.LOCATION_ID = 1700

SELECT *
  FROM EMPLOYEES emp
  WITH (INDEX (EMP_EMP_ID_PK))
  JOIN DEPARTMENTS dep
  WITH (INDEX (DEPT_ID_PK, DEPT_LOCATION_IX))
    ON dep.DEPARTMENT_ID = emp.DEPARTMENT_ID
   AND dep.LOCATION_ID = 1700

/******************************************************************************/
/* FUNCTION                                                                   */
/******************************************************************************/

/* Contoh proses sederhana, menggunakan SQL statement */
SELECT LTRIM(RTRIM('                     Test                     '))

/* SCALAR FUNCTION ************************************************************/

/* Pembuatan scalar FUNCTION berisi contoh proses sederhana */
CREATE FUNCTION ScalarLTrimR(@StrToTrim NVARCHAR(200))
RETURNS NVARCHAR (200) AS
BEGIN
   RETURN LTRIM(RTRIM(@StrToTrim))
END

/* Pemanggilan scalar FUNCTION, dilakukan pada SELECT clause */
SELECT dbo.ScalarLTrimR('                     Test                     ')

/* Sama seperti built-in scalar FUNCTION */
SELECT getdate ()

/* Pemanggilan scalar FUNCTION terhadap TABLE */
SELECT dbo.ScalarLTrimR (FIRST_NAME) FROM EMPLOYEES

/* Pembuatan scalar FUNCTION untuk men-generate alamat email */
 CREATE FUNCTION ScalarCreateEmail(@StrToEmail NVARCHAR(200))
RETURNS NVARCHAR (200) AS
  BEGIN
 RETURN @StrToEmail + '@uib.edu'
    END

/* Pemanggilan scalar FUNCTION terhadap beberapa COLUMN dalam TABLE */
SELECT dbo.ScalarCreateEmail (FIRST_NAME),
       dbo.ScalarLTrimR (FIRST_NAME)
  FROM EMPLOYEES

/* INLINE TABLE-VALUED FOR SCALAR *********************************************/

/* Penggunaan ITV FUNCTION dengan RETURN menyerupai scalar */
   CREATE FUNCTION ITVLTrimR(@StrToTrim NVARCHAR(200))
  RETURNS TABLE
       AS
   RETURN (SELECT LTRIM(RTRIM(@StrToTrim)) AS Trimmed)

SELECT * FROM dbo.ITVLTrimR('                     Test                     ')

/* Pemanggilan ITV FUNCTION dengan RETURN menyerupai scalar terhadap TABLE */
SELECT emp.Trimmed
FROM EMPLOYEES
CROSS APPLY dbo.ITVLTrimR (FIRST_NAME) AS emp

/* INLINE TABLE-VALUED FUNCTION ***********************************************/

/* Pembuatan ITV Function */
CREATE FUNCTION ITVDepLoc()
  RETURNS TABLE
      AS RETURN
         SELECT dep.DEPARTMENT_NAME, loc.CITY
           FROM DEPARTMENTS dep
     INNER JOIN LOCATIONS loc ON dep.LOCATION_ID = loc.LOCATION_ID

/* Pemanggilan ITV FUNCTION, dilakukan pada FROM clause */
SELECT *
  FROM ITVDepLoc()
 WHERE CITY = 'Seattle'

CREATE FUNCTION ITVDepLocByCity(@StrCity NVARCHAR(200))
  RETURNS TABLE
      AS RETURN
         SELECT dep.DEPARTMENT_NAME, loc.CITY
           FROM DEPARTMENTS dep
     INNER JOIN LOCATIONS loc ON dep.LOCATION_ID = loc.LOCATION_ID
            AND LOC.CITY = @StrCity

select * from locations where city ='Seattle' OR '1'='1'
SELECT * FROM ITVDepLocByCity ('Seattle' OR '1'='1')

/* MULTI-STATEMENT TABLE-VALUED FUNCTION **************************************/

/* Pembuatan MSTV FUNCTION */
    CREATE FUNCTION MTVGetManager ()
   RETURNS @Manager TABLE (FIRST_NAME NVARCHAR(64), LAST_NAME NVARCHAR(64), DEPARTMENT_ID INT, MANAGER_ID INT)
        AS
     BEGIN
   DECLARE @Director INT
    SELECT @Director = EMPLOYEE_ID
      FROM EMPLOYEES
     WHERE MANAGER_ID IS NULL
    INSERT @Manager
    SELECT FIRST_NAME, LAST_NAME, DEPARTMENT_ID, MANAGER_ID
      FROM EMPLOYEES
     WHERE MANAGER_ID = @Director
    RETURN
       END

/* Pemanggilan MSTV FUNCTION, dilakukan pada FROM clause */
SELECT *
  FROM MTVGetManager ()
 WHERE DEPARTMENT_ID = 20

/* Pembuatan MSTV FUNCTION, menampilkan data manager berdasarkan departemen */
    CREATE FUNCTION MTVGetManagerByDep (@DEPARTMENT_ID INT)
   RETURNS @Manager TABLE (FIRST_NAME NVARCHAR(64), LAST_NAME NVARCHAR(64), DEPARTMENT_ID INT, MANAGER_ID INT)
        AS
     BEGIN
   DECLARE @Director INT
    SELECT @Director = EMPLOYEE_ID
      FROM EMPLOYEES
     WHERE MANAGER_ID IS NULL
    INSERT @Manager
    SELECT FIRST_NAME, LAST_NAME, DEPARTMENT_ID, MANAGER_ID
      FROM EMPLOYEES
     WHERE MANAGER_ID = @Director
       AND DEPARTMENT_ID = @DEPARTMENT_ID
    RETURN
       END

/* Pemanggilan ITV FUNCTION dengan parameter */
SELECT *
  FROM MTVGetManagerByDep (90)

/******************************************************************************/
/* TRIGGER                                                                    */
/******************************************************************************/

/* TRIGGER untuk menampilkan nilai lama dan nilai baru */
 CREATE TRIGGER tr_countries ON COUNTRIES
          AFTER INSERT, UPDATE, DELETE
             AS
          BEGIN
	         IF @@ROWCOUNT = 0 RETURN;
         SELECT ins.*,
                del.*
           FROM inserted ins
FULL OUTER JOIN deleted del ON ins.country_id = del.country_id
            END

SELECT * FROM COUNTRIES

/* Saat eksekusi DML2 berikut, TRIGGER akan secara otomatis tereksekusi */
INSERT INTO COUNTRIES (COUNTRY_ID, COUNTRY_NAME, REGION_ID) VALUES ('ID', 'Indonesia', 2)

UPDATE COUNTRIES SET REGION_ID = 3 WHERE COUNTRY_ID = 'ID'

DELETE COUNTRIES WHERE COUNTRY_ID = 'ID'

/* TRIGGER untuk mengubah nilai baru pada saat INSERT dan UPDATE */
CREATE TRIGGER tr_emp_sal_cheat ON EMPLOYEES
           FOR INSERT, UPDATE
            AS
         BEGIN
         IF @@ROWCOUNT = 0 RETURN;
        UPDATE EMPLOYEES
           SET SALARY = ins.salary * 1.1
          FROM EMPLOYEES emp
          JOIN inserted ins ON emp.employee_id = ins.employee_id
           END

SELECT * FROM EMPLOYEES

/* Contoh eksekusi otomatis TRIGGER saat eksekusi DML */
UPDATE EMPLOYEES SET SALARY = 42000 WHERE EMPLOYEE_ID = 100

/******************************************************************************/
/* PROCEDURE                                                                  */
/******************************************************************************/

    IF OBJECT_ID ( 'GetAllLoc', 'P' ) IS NOT NULL 
  DROP PROCEDURE HumanResources.usp_GetAllEmployees;

/* Pembuatan PROCEDURE, tanpa parameter */
CREATE PROCEDURE GetAllLoc
    AS
SELECT LOC.CITY, COU.COUNTRY_NAME
  FROM LOCATIONS LOC
  JOIN COUNTRIES COU
    ON LOC.COUNTRY_ID = COU.COUNTRY_ID

/* Pemanggilan PROCEDURE, tanpa parameter */
GetAllLoc

EXECUTE GetAllLoc

EXEC GetAllLoc

/* Pembuatan PROCEDURE, mengunakan parameter */
CREATE PROCEDURE GetEmpByName @lastname varchar(40), @firstname varchar(20)
    AS 
SELECT EMP.FIRST_NAME + ' ' + EMP.LAST_NAME EMPLOYEE_NAME, DEP.DEPARTMENT_NAME
  FROM EMPLOYEES EMP
  JOIN DEPARTMENTS DEP
    ON EMP.DEPARTMENT_ID = DEP.DEPARTMENT_ID
   AND EMP.FIRST_NAME = @firstname
   AND EMP.LAST_NAME = @lastname

/* Pemanggilan PROCEDURE, mengunakan parameter */
GetEmpByName  @firstname = 'Steven', @lastname = 'King'

EXECUTE GetEmpByName @firstname = 'Steven', @lastname = 'King'

EXECUTE GetEmpByName @lastname = 'King', @firstname = 'Steven'

EXEC GetEmpByName @firstname = 'Steven', @lastname = 'King'

EXEC GetEmpByName @lastname = 'King', @firstname = 'Steven'

EXEC GetEmpByName 'King', 'Steven'

/* Pembuatan PROCEDURE, mengunakan parameter OUTPUT */
CREATE PROCEDURE GetEmpBySalary @minsalary INT,
                                @maxsalary INT,
                                @avgsalary INT OUTPUT,
                                @actualavgsalary INT OUT
AS
SELECT EMP.FIRST_NAME + ' ' + EMP.LAST_NAME EMPLOYEE_NAME, EMP.SALARY
  FROM EMPLOYEES EMP
 WHERE EMP.SALARY BETWEEN @minsalary AND @maxsalary;
   SET @actualavgsalary = (
SELECT AVG (EMP.SALARY)
  FROM EMPLOYEES EMP
 WHERE EMP.SALARY BETWEEN @minsalary AND @maxsalary);
   SET @avgsalary = (@minsalary + @maxsalary) / 2;

/* Pemanggilan PROCEDURE, mengunakan parameter OUTPUT */
DECLARE @avgsalary INT, @actualavgsalary INT 
EXECUTE GetEmpBySalary 5000, 10000, @avgsalary OUT, @actualavgsalary OUTPUT
  BEGIN
  PRINT 'These Employees share actual average salary of '+ RTRIM (CAST (@actualavgsalary AS varchar(20))) +' meanwhile the average for input parameters is ' + RTRIM (CAST (@avgsalary AS varchar(20))) + '.'
    END



















