Foreign key

From: "Patrick Welche" <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Foreign key
Date: 1999-12-15 22:56:10
Message-ID: E11yNL8-0002NE-00@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

How do they work?

Date: Wed, 6 Oct 1999 15:25:27 +0000 (GMT)
Subject: Re: [GENERAL] Foreign Key
Message-ID: <Pine(dot)LNX(dot)3(dot)96(dot)991006152248(dot)8877H-100000(at)rabies(dot)toodarkpark(dot)org>

I had a look at the above message which involved the refint contrib code. I
thought the equivalent might be:

CREATE TABLE employee
(
emp_id serial primary key,
emp_name varchar(30) NOT NULL
);

CREATE TABLE emp_expense
(
expense_id serial primary key,
emp_id int4 references employee match full on update cascade,
descr varchar(100) NOT NULL,
ondate date not null
);

insert into employee values (2,'Myself');
insert into emp_expense values (1,2,'Test','10-06-1999');
insert into emp_expense values (2,2,'Test #2','10-06-1999');
select * from employee;
select * from emp_expense;
update employee set emp_id=5;
select * from emp_expense; -- hope emp_id magically changes to 5

but obviously it can't be, as if I update employee, there is nothing in table
employee to say "take a look at emp_expense and update emp_id over there".
There only is something in emp_expense to say "check employee to see that
emp_id here is valid".

Anyone know of a tutorial/give me a hint?

Cheers,

Patrick

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 1999-12-15 23:46:53 Re: [GENERAL] server hardware recommendations (the archives are dead)
Previous Message Mike Mascari 1999-12-15 20:56:08 Re: [GENERAL] server hardware recommendations (the archives aredead)