0% found this document useful (0 votes)
20 views2 pages

تكليف قواعد البيانات مهند علي علي علي سعد الاخير

The document outlines the SQL schema for a database consisting of six tables: locations, regions, countries, departments, jobs, and employees. Each table is defined with its respective columns, data types, and primary/foreign key constraints to establish relationships between them. The schema facilitates the organization and management of data related to employees, their jobs, and the locations they operate in.

Uploaded by

gdnjavjhdjdh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

تكليف قواعد البيانات مهند علي علي علي سعد الاخير

The document outlines the SQL schema for a database consisting of six tables: locations, regions, countries, departments, jobs, and employees. Each table is defined with its respective columns, data types, and primary/foreign key constraints to establish relationships between them. The schema facilitates the organization and management of data related to employees, their jobs, and the locations they operate in.

Uploaded by

gdnjavjhdjdh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CREATE TABLE locations (

location_id NUMBER PRIMARY KEY,


street_address VARCHAR2(100),
postal_code VARCHAR2(20),
city VARCHAR2(50),
state_province VARCHAR2(50),
country_id CHAR(2),CONSTRAINT fk_country
FOREIGN KEY(country_id)
REFERENCES countries(country_id)
);

CREATE TABLE regions (


region_id NUMBER PRIMARY KEY,
region_name VARCHAR2(50)
);

CREATE TABLE countries (


country_id CHAR(2) PRIMARY KEY,
country_name VARCHAR2(50),
region_id NUMBER,
CONSTRAINT fk_region
FOREIGN KEY (region_id)
REFERENCES regions(region_id)
);

CREATE TABLE departments (


department_id NUMBER PRIMARY KEY,
department_name VARCHAR2(50),
location_id NUMBER,
manager_id NUMBER,
CONSTRAINT fk_location
FOREIGN KEY (location_id)
REFERENCES locations(location_id)
);

CREATE TABLE jobs (


job_id VARCHAR2(10) PRIMARY KEY,
job_title VARCHAR2(50),
min_salary NUMBER,
max_salary NUMBER
);

CREATE TABLE employees (


employee_id NUMBER PRIMARY KEY,
first_name VARCHAR2(50),
last_name VARCHAR2(50),
email VARCHAR2(100),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER,
commission_pct NUMBER,
manager_id NUMBER,
department_id NUMBER,
CONSTRAINT fk_job
FOREIGN KEY (job_id)
REFERENCES jobs(job_id),
CONSTRAINT fk_department
FOREIGN KEY (department_id)
REFERENCES departments(department_id)
);

CREATE TABLE job_history (


employee_id NUMBER,
start_date DATE,
end_date DATE,
job_id VARCHAR2(10),
department_id NUMBER,
PRIMARY KEY (employee_id, start_date),
CONSTRAINT fk_job_history_employee
FOREIGN KEY (employee_id)
REFERENCES employees(employee_id),
CONSTRAINT fk_job_history_job
FOREIGN KEY (job_id)
REFERENCES jobs(job_id),
CONSTRAINT fk_job_history_department
FOREIGN KEY (department_id)
REFERENCES departments(department_id)
);

You might also like