For example, say I have something like
CREATE TABLE COMPANY(id int not null primary key, ...);
CREATE TABLE DEPARTMENT(id int not null primary key, company_id int not null,
CONSTRAINT FK_DEP_COMPANY_ID FOREIGN KEY(company_id) REFERENCES COMPANY(id),...);
CREATE TABLE EMPLOYEE(id int not null primary key, department_id int not null,
username varchar(30) NOT NULL, ...,
CONSTRAINT FK_EMPLOYEE_DEP_ID FOREIGN KEY(department_id) REFERENCES DEPARTMENT(id));
I have to implement uniqueness of EMPLOYEE.username within one company.
I see 2 ways.
1. Using AFTER statement level trigger on EMPLOYEE table (something similar to http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551198119097816936 , case1)
2. Just adding company_id to EMPLOYEE
Neither of them looks ideal to me, and I wonder what is the proper way to implement uniqueness in such case.
Thanks.
usersis the same as indepartments… I believe the right way involves redesigning schema (and implementing of Party-Role-Relationship), but I cannot do that at the moment, so I 'm trying to find alternatives which require minimal changes to the model. – a1ex07 Jan 27 '12 at 14:06department) to getcompany_id. Such a function is not deterministic by nature; however, function based index requires function to be deterministic. – a1ex07 Jan 30 '12 at 14:45