Вы находитесь на странице: 1из 6

CREATE TABLE departments

(
department_id NUMBER(4) NOT NULL,
department_name VARCHAR2(30) NOT NULL,
manager_id NUMBER(6),
location_id NUMBER(4),
constraint pk_depts PRIMARY KEY(department_id)
);
CREATE TABLE employees
(
employee_id NUMBER(6) NOT NULL,
first_name VARCHAR(20),
last_name VARCHAR(25) NOT NULL,
email VARCHAR(25) NOT NULL,
phone_number VARCHAR(20),
hire_date DATE NOT NULL,
job_id VARCHAR2(10) NOT NULL,
salary NUMBER(8,2),
commission_pct NUMBER(2,2),
manager_id NUMBER(6),
department_id NUMBER(4),
CONSTRAINT fk_depts FOREIGN KEY(department_id) references departments(department
_id)
);
CREATE TABLE job_grades
(
grade_level VARCHAR2(3),
lowest_sal NUMBER,
highest_sal NUMBER
);

INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_


date,job_id,
salary,department_id)
VALUES(100,'Steven','King','SKING','515.123.4567','17-jun-1987','AD_PRES',24000,
90);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(101,'Neena','Kochhar','NKOCHHAR','515.123.4568','21-sep-1989','AD_VP',170
00,100,90);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(102,'Lex','De Haan','LDEHAAN','515.123.4569','13-jan-1993','AD_VP',17000,
100,90);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(103,'Alexander','Hunold','AHUNOLD','590.423.4567','03-jan-1990','IT_PROG'
,9000,102,
60);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(104,'Bruce','Ernst','BERNST','590.423.4568','21-may-1991','IT_PROG',6000,
103,60);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(107,'Diana','Lorentz','DLORENTZ','590.423.5567','07-feb-1999','IT_PROG',4
200,103,60);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(124,'Kevin','Mourgos','KMOURGOS','650.123.5234','16-nov-1999','ST_MAN',58
00,100,50);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(141,'Trenna','Rajs','TRAJS','650.121.8009','17-oct-1995','ST_CLERK',3500,
124,50);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(142,'Curtis','Davies','CDAVIES','650.121.2994','29-jan-1997','ST_CLERK',3
100,124,50);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(143,'Randall','Matos','RMATOS','650.121.2874','15-mar-1998','ST_CLERK',26
00,124,50);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(144,'Peter','Vargas','PVARGAS','650.121.2004','09-jul-1998','ST_CLERK',25
00,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(149,'Eleni','Zlotkey','EZLOTKEY','011.44.1344.429018','29-jan-2000','SA_M
AN',10500,
.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(174,'Ellen','Abel','EABEL','011.44.1644.429267','11-may-1996','SA_REP',11
000,.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(176,'Jonathon','Taylor','JTAYLOR','011.44.1644.429265','24-mar-1998','SA_
REP',8600,.2,
149,80);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,commission_pct,manager_id)
VALUES(178,'Kimberely','Grant','KGRANT','011.44.1644.429263','24-may-1999','SA_R
EP',7000,
.15,149);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(200,'Jennifer','Whalen','JWHALEN','515.123.4444','17-sep-1987','AD_ASST',
4400,101,
10);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(201,'Michael','Hartstein','MHARTSTE','515.123.5555','17-feb-1996','MK_MAN
',13000,
100,20);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(202,'Pat','Fay','PFAY','603.123.6666','17-aug-1997','MK_REP',6000,201,20)
;
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(205,'Shelley','Higgins','SHIGGINS','515.123.8080','07-jun-1994','AC_MGR',
12000,101,
110);
INSERT INTO employees (employee_id,first_name,last_name,email,phone_number,hire_
date,job_id,
salary,manager_id,department_id)
VALUES(206,'William','Gietz','WGIETZ','515.123.8181','07-jun-1994','AC_ACCOUNT',
8300,205,110);
--------------------------------------------------------------------------------
-------------
--------------------------------------------------------------------------------
-------------

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(50,'Shipping',124,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(80,'Sales',149,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(110,'Accounting',205,1700);
INSERT INTO departments (department_id,department_name,location_id)
VALUES(190,'Contracting',1700);

--------------------------------------------------------------------------------
-------------
--------------------------------------------------------------------------------
-------------

INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)


VALUES('A',1000,2999);
INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)
VALUES('B',3000,5999);
INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)
VALUES('c',6000,9999);
INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)
VALUES('D',10000,14999);
INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)
VALUES('E',15000,24999);
INSERT INTO job_grades (grade_level,lowest_sal,highest_sal)
VALUES('F',25000,40000);
--------------------------------------------------------------------------------
--------------
--------------------------------------------------------------------------------
--------------
SQL> CREATE TABLE locations
2 (
3 location_id NUMBER(4) PRIMARY KEY,
4 street_address VARCHAR2(40),
5 postal_code VARCHAR2(12),
6 city VARCHAR2(30) NOT NULL,
7 state_province VARCHAR2(25),
8 country_id CHAR(2)
9 );
Table created.
SQL> DROP TABLE locations;
Table dropped.
SQL> CREATE TABLE locations
2 (
3 location_id PRIMARY KEY NUMBER(4),
4 street_address VARCHAR2(40),
5 postal_code VARCHAR2(12),
6 city NOT NULL VARCHAR2(30),
7 state_province VARCHAR2(25),
8 country_id CHAR(2)
9 );
location_id PRIMARY KEY NUMBER(4),
*
ERROR at line 3:
ORA-00907: missing right parenthesis

SQL> CREATE TABLE locations


2 (
3 street_address VARCHAR2(40),
4 postal_code VARCHAR2(12),
5 city NOT NULL VARCHAR2(30),
6 state_province VARCHAR2(25),
7 country_id CHAR(2)
8 );
city NOT NULL VARCHAR2(30),
*
ERROR at line 5:
ORA-00907: missing right parenthesis

CREATE TABLE locations


(
location_id NUMBER(4) PRIMARY KEY,
street_address VARCHAR2(40),
postal_code VARCHAR2(12),
city VARCHAR2(30) NOT NULL,
state_province VARCHAR2(25),
country_id CHAR(2)
);
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(1700,'2004 Charade Rd','98199','Seattle','Washington','US');
INSERT INTO locations(location_id,street_address,postal_code,city,state_province
,country_id)
VALUES(1800,'460 Bloor St. W.','ON M5S 1X8','Toronto','Ontario','CA');
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','Oxfor
d','UK');
--------------------------------------------------------------------------------
-----------------
--------------------------------------------------------------------------------
-----------------