Sei sulla pagina 1di 2

Creating table REGIONS:

=======================

drop table REGIONS;


Create table REGIONS
(REGIONID number(4) constraint REGIONS_C1_REGIONID PRIMARY KEY,
REGIONNAME varchar2(25));

Creating table COUNTRIES:


=========================

drop table COUNTRIES;


Create table COUNTRIES
(COUNTRYID number(4) constraint COUNTRIES_C1_COUNTRYID PRIMARY KEY,
COUNTRYNAME varchar2(40),
REGIONID number(5));

alter table COUNTRIES add constraint COUNTRIES_C2_REGIONID FOREIGN KEY(REGIONID)


REFERENCES REGIONS(REGIONID);

Creating table LOCATIONS:


=========================

drop table LOCATIONS;


create table LOCATIONS
(LOCATIONID number(5) constraint LOCATIONS_C1_LOCATIONID PRIMARY KEY,
STREETADDRESS varchar2(25),
POSTALCODE varchar2(12),
CITY varchar2(30),
STATEPROVINCE varchar2(12),
COUNTRYID number(4));

alter table LOCATIONS add constraint LOCATIONS_C2_COUNTRYID FOREIGN KEY(COUNTRYID)


REFERENCES COUNTRIES(COUNTRYID);

Creating table EMPLOYEES:


=========================

drop table EMPLOYEES;

Create table EMPLOYEES


(EMPLOYEEID number(5) constraint EMPLOYEES_C1_EMPLOYEEID PRIMARY KEY,
FIRSTNAME varchar2(20),
LASTNAME varchar2(25),
EMAIL varchar2(25),
PHONENUMBER varchar2(20),
HIREDATE date,
JOBID varchar2(10),
SALARY number(7,2),
COMMISSIONPCT number,
MANAGERID number(5),
DEPARTMENTID number(5));

alter table EMPLOYEES add constraint EMPLOYEES_C2_DEPARTMENTID FOREIGN


KEY(DEPARTMENTID) REFERENCES DEPARTMENTS(DEPARTMENTID);

alter table EMPLOYEES add constraint EMPLOYEES_c2_EMPLOYEEID FOREIGN


KEY(EMPLOYEEID) REFERENCES JOBHISTORY(EMPLOYEEID);

alter table EMPLOYEES add constraint EMPLOYEES_C3_JOBID FOREIGN KEY(JOBID)


REFERENCES JOBS(JOBID);

Creating table DEPARTMENTS:


===========================

drop table DEPARTMENTS:

Create table DEPARTMENTS


(DEPARTMENTID number(5) constraint DEPARTMENTS_c1_DEPARTMENTID PRIMARY KEY,
DEPARTMENTNAME varchar2(30),
MANAGERID number(5),
LOCATIONID number(5));

alter table DEPARTMENTS add constraint DEPARTMENTS_c2_LOCATIONID FOREIGN


KEY(LOCATIONID) REFERENCES LOCATIONS(LOCATIONID);

Creating table JOBHISTORY:


==========================

drop table JOBHISTORY;

Create table JOBHISTORY


(EMPLOYEEID number(5) constraint JOBHISTORY_C1_EMPLOYEEID PRIMARY KEY,
STARTDATE date,
ENDDATE date,
JOBID varchar2(10),
DEPARTMENTID number(5));

alter table JOBHISTORY add constraint JOBHISTORY_C2_DEPARTMENTID FOREIGN


KEY(DEPARTMENTID) REFERENCES DEPARTMENTS(DEPARTMENTID);

alter table JOBHISTORY add constraint JOBHISTORY_C2_JOBID FOREIGN KEY(JOBID)


REFERENCES JOBS(JOBID);

Creating table JOBS:


====================

drop table JOBS;

create table JOBS


(JOBID varchar2(10) constraint JOBS_C1_JOBID PRIMARY KEY,
JOBTITLE varchar2(35),
MINSALARY number(7,2),
MAXSALARY number(7,2));

Creating table JOBGRADES:


=========================

drop table JOBGRADES;

Create table JOBGRADES


(GRADELEVEL varchar2(10) constraint JOBGRADES_C1_GRADELEVEL PRIMARY KEY,
LOWESTSAL number(7,2),
HIGHESTSAL number(7,2));

Potrebbero piacerti anche