If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > timespan primary key

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-24-06, 14:28
teniosoft teniosoft is offline
Registered User
 
Join Date: Mar 2003
Location: Portland, Or
Posts: 21
timespan primary key

Hi I would like to make it so that two rows can not exist in the same timespan, interval or between the same period (I really am not quite sure what the correct terminology for this is). Example to appointments can not conflict.

I am using Postgres 8.1 for my database but would like a sollution that would work with all databases (or most). Does anyone know how I could accomplish this.

Stephen
__________________
Stephen Rich
http://www.teniosoft.com
Web Applications, Client Server Databases for Linux and Windows
Reply With Quote
  #2 (permalink)  
Old 03-24-06, 14:57
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Cool


Do as the title of your post says: Create primary key on "patient_id"+"appointment date/time"



__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 03-24-06, 16:23
teniosoft teniosoft is offline
Registered User
 
Join Date: Mar 2003
Location: Portland, Or
Posts: 21
This does not handle a span of time you could have an appointment for 30 minutes but the database would still allow you to insert an appointment at 12:30 and then 12:31 and so on and so forth.
__________________
Stephen Rich
http://www.teniosoft.com
Web Applications, Client Server Databases for Linux and Windows
Reply With Quote
  #4 (permalink)  
Old 03-27-06, 08:13
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
If your DBMS supports the ANSI "CREATE ASSERTION" syntax then you could use that. It would be something like:
Code:
CREATE ASSERTION x CHECK
NOT EXISTS
( SELECT NULL FROM appointments a, appointments b
  WHERE a.patient_id = b.patient_id
  AND a.start <= b.end
  AND b.start <= a.end
);
However, Oracle for one DBMS does not support assertions, and you would have to use other methods e.g. triggers or materialized views with constraints.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On