From: | Bill Moran <wmoran(at)potentialtech(dot)com> |
---|---|
To: | finecur <finecur(at)yahoo(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: constrains on two tables |
Date: | 2007-09-14 19:18:21 |
Message-ID: | 20070914151821.e000fca0.wmoran@potentialtech.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
In response to finecur <finecur(at)yahoo(dot)com>:
> On Sep 10, 9:55 pm, finecur <fine(dot)(dot)(dot)(at)yahoo(dot)com> wrote:
> > Hi
> >
> > 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, but not in the course
> > table, nor in department. I would like to make the course_number
> > unique in the scope of School. So, you may see the same course_number
> > in Course table, but (school_id, course_number) should be always
> > unique. How can I make the constrain?
ALTER TABLE Course PRIMARY KEY(school_id, course_number);
and add the school_id column to the Course table.
--
Bill Moran
http://www.potentialtech.com
From | Date | Subject | |
---|---|---|---|
Next Message | Gregory Stark | 2007-09-14 19:34:02 | Re: NOT NULL Issue |
Previous Message | Bruce Momjian | 2007-09-14 19:02:54 | Re: [HACKERS] AutoVacuum Behaviour Question |