Subject | How to prevent duplicates with a startdate - stopdate construction |
---|---|
Author | Nikolaus Kern |
Post date | 2010-05-18T15:19:19Z |
Hello all,
Using now Firebird for some time I am facing now a question where I am
simply stuck.
*) There is a simple table to store the allocation of employees to
specific projects
*) Its stored with a start- and enddate
*) The database should check now if the same employee is booked to the
same or an overlapping timeframe
The code below works perfect until a BAUSTELLE (= project) is renamed.
In this case the CHECK condition fires and seems to find itself.
Is there something like a rowID I could use in this context?
Thanks a lot in advance
Niko
***********************************************
CREATE TABLE DETAILPLANUNG (
BAUSTELLE CHAR(30) CHARACTER SET NONE NOT NULL COLLATE NONE,
MITARBEITER INTEGER,
STARTDATUM DATE,
STOPDATUM DATE);
ALTER TABLE DETAILPLANUNG ADD CONSTRAINT CHK_DETAILPLANUNG CHECK (EXISTS
(SELECT
*
FROM DETAILPLANUNG
WHERE MITARBEITER = NEW.MITARBEITER AND
((NEW.STARTDATUM BETWEEN STARTDATUM AND STOPDATUM) OR
(NEW.STOPDATUM BETWEEN STARTDATUM AND STOPDATUM)) ));
Using now Firebird for some time I am facing now a question where I am
simply stuck.
*) There is a simple table to store the allocation of employees to
specific projects
*) Its stored with a start- and enddate
*) The database should check now if the same employee is booked to the
same or an overlapping timeframe
The code below works perfect until a BAUSTELLE (= project) is renamed.
In this case the CHECK condition fires and seems to find itself.
Is there something like a rowID I could use in this context?
Thanks a lot in advance
Niko
***********************************************
CREATE TABLE DETAILPLANUNG (
BAUSTELLE CHAR(30) CHARACTER SET NONE NOT NULL COLLATE NONE,
MITARBEITER INTEGER,
STARTDATUM DATE,
STOPDATUM DATE);
ALTER TABLE DETAILPLANUNG ADD CONSTRAINT CHK_DETAILPLANUNG CHECK (EXISTS
(SELECT
*
FROM DETAILPLANUNG
WHERE MITARBEITER = NEW.MITARBEITER AND
((NEW.STARTDATUM BETWEEN STARTDATUM AND STOPDATUM) OR
(NEW.STOPDATUM BETWEEN STARTDATUM AND STOPDATUM)) ));