diff options
| author | mo khan <mo.khan@gmail.com> | 2020-01-17 20:37:02 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-01-17 20:37:02 -0700 |
| commit | 69eef411ae3c72f198ee1588b911046373c9eef8 (patch) | |
| tree | 5271a001ad9813c710c2b732e9074598230fe253 | |
| parent | 5e23312b4f9cc71e5f9a6852e519f34e48e23597 (diff) | |
Ready for submission
| -rw-r--r-- | assignments/1/README.md | 35 | ||||
| -rw-r--r-- | assignments/1/README.pdf | bin | 232888 -> 256048 bytes |
2 files changed, 35 insertions, 0 deletions
diff --git a/assignments/1/README.md b/assignments/1/README.md index 1855b10..d876d93 100644 --- a/assignments/1/README.md +++ b/assignments/1/README.md @@ -153,6 +153,41 @@ Consider a one-relation database with the following attributes: * Foreign key constraints ensure that a valid corresponding relation must exist in the relation that the foreign key references. * A unique constraint on `departments(manager_id);` to ensure an employee cannot manage more than one department. +Example postgresql SQL: +```sql +CREATE TABLE employees ( + id bigint primary key, + department_id bigint, + project_id bigint, + hired_at date, + title varchar(255), + area varchar(255), + salary decimal +); + +CREATE TABLE departments ( + id bigint primary key, + manager_id bigint references employees(id), + budget decimal +); + +CREATE TABLE projects ( + id bigint primary key, + department_id bigint references departments(id), + budget decimal +); + +CREATE TABLE phones (number varchar(255) primary key, employee_id bigint references employees(id)); +CREATE TABLE offices (number varchar(255) primary key, employee_id bigint references employees(id)); + +ALTER TABLE employees ADD CONSTRAINT departments_fk FOREIGN KEY (department_id) REFERENCES departments(id); +ALTER TABLE employees ADD CONSTRAINT projects_fk FOREIGN KEY (project_id) REFERENCES projects(id); + +CREATE UNIQUE INDEX department_manager_idx on departments(manager_id); +CREATE UNIQUE INDEX employee_phones_idx on phones(employee_id); +CREATE UNIQUE INDEX employee_offices_idx on offices(employee_id); +``` + ## Question 6 Consider the following relations: diff --git a/assignments/1/README.pdf b/assignments/1/README.pdf Binary files differindex 8a74b0b..95aea85 100644 --- a/assignments/1/README.pdf +++ b/assignments/1/README.pdf |
