Skip to content

Commit f397396

Browse files
Update UNIQUE constraint to include FKs for COMPANY, POSITION and EMPLOYEE
1 parent 057ad0a commit f397396

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

code/SQL/100-040 DB SETUP - CREATE TABLE Job.sql

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
CREATE TABLE IF NOT EXISTS paylocity.dev.Job
77
(
8-
guid uuid PRIMARY KEY,
9-
company_guid uuid NOT NULL,
10-
position_guid uuid NOT NULL,
11-
employee_guid uuid NOT NULL,
12-
FOREIGN KEY (company_guid) REFERENCES paylocity.dev.Company (guid),
13-
FOREIGN KEY (position_guid) REFERENCES paylocity.dev.Position (guid),
14-
FOREIGN KEY (employee_guid) REFERENCES paylocity.dev.Employee (guid),
15-
UNIQUE (company_guid, employee_guid)
16-
);
8+
guid uuid NOT NULL,
9+
company_guid uuid NOT NULL,
10+
position_guid uuid NOT NULL,
11+
employee_guid uuid NOT NULL,
12+
CONSTRAINT Job_PK PRIMARY KEY (guid),
13+
CONSTRAINT Job_FK_company_guid FOREIGN KEY (company_guid) REFERENCES paylocity.dev.Company (guid),
14+
CONSTRAINT Job_FK_position_guid FOREIGN KEY (position_guid) REFERENCES paylocity.dev.Position (guid),
15+
CONSTRAINT Job_FK_employee_guid FOREIGN KEY (employee_guid) REFERENCES paylocity.dev.Employee (guid),
16+
CONSTRAINT Job_unique_comp_pos_emp UNIQUE (company_guid, position_guid, employee_guid)
17+
);
18+
19+
COMMENT ON CONSTRAINT Job_unique_comp_pos_emp ON paylocity.dev.Job
20+
IS 'Prevent same person from having same job at same company';

0 commit comments

Comments
 (0)