Unix Technical Forum

unique constratin - not in the table

This is a discussion on unique constratin - not in the table within the pgsql Sql forums, part of the PostgreSQL category; --> Hi I have a problem to make constrains across two tables. I am not sure if this can be ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 05:54 PM
finecur
 
Posts: n/a
Default unique constratin - not in the table

Hi

I have a problem to make constrains across two tables. I am not sure
if this can be down in postgresql.

Here is my table:


Table School
(
id integer,
name text
);


Table Department
(
id integer,
school_id integer reference school(id),
name text
);


Table Course
(
department_id integer references department(id),
name text,
course_number text
)


I would like to make the course_number unique, not in scope of
Department but in the scope of School. So, you may see the same
combination of (department_id, course_number) in the Course table, but
if you pull out (school_id, course_number) list from from a joint
query, you will find the combination is unique. How can I make this
constrain?


Thanks,


ff

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 05:54 PM
Sascha Bohnenkamp
 
Posts: n/a
Default Re: unique constratin - not in the table

> I have a problem to make constrains across two tables. I am not sure
> if this can be down in postgresql.

just store the course-numbers in their own table as primary key
and reference them from the other tables
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:54 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com