unique constraint on more than one tables

From: Akbar <akbarhome(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: unique constraint on more than one tables
Date: 2006-12-28 12:01:08
Message-ID: 5e8843f90612280401t1a7197b3u7a3e8ca44379784d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

Imagine I have two tables, like this:

create table bla_a (
id serial primary key,
name varchar(31) not null,
comment varchar(31)
);

create table bla_b (
id serial primary key,
name varchar(31) not null,
blabla int
);

I want to make sure that both tables could not have the same value for
name column. Can I do that?

insert into bla_a ( id, name, comment ) values ( 1, 'bo', 'ha');
insert into bla_b ( id, name, comment ) values ( 1, 'bo', 3);

I want to make the second insertion failed because of unique
constraint. Can I do that?

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Akbar 2006-12-28 12:09:33 select union with table name
Previous Message Carlos H. Reimer 2006-12-28 11:39:34 Improve response time of a SQL command