Received: from mail.enterprise.net (mail.enterprise.net [194.72.192.18]) by hub.org (8.10.1/8.10.1) with ESMTP id e6A9H1W94182 for ; Mon, 10 Jul 2000 05:17:01 -0400 (EDT) Received: from linda.lfix.co.uk (cmax02-101.enterprise.net [212.161.113.101]) by mail.enterprise.net (8.8.5/8.8.5) with ESMTP id KAA06097; Mon, 10 Jul 2000 10:16:59 +0100 (GMT/BST) Received: from lfix.co.uk (olly@localhost [127.0.0.1]) by linda.lfix.co.uk (8.11.0.Beta1/8.11.0.Beta1/Debian 8.11.0-1) with ESMTP id e6A9GUc12505; Mon, 10 Jul 2000 10:16:30 +0100 Message-Id: <200007100916.e6A9GUc12505@linda.lfix.co.uk> X-Authentication-Warning: linda.lfix.co.uk: Host olly@localhost [127.0.0.1] claimed to be lfix.co.uk X-Mailer: exmh version 2.1.1 10/15/1999 (debian) X-URL: http://www.lfix.co.uk/oliver X-face: "xUFVDj+ZJtL_IbURmI}!~xAyPC"Mrk=MkAm&tPQnNq(FWxv49R}\>0oI8VM?O2VY+N7@F- KMLl*!h}B)u@TW|B}6 cc: "PGSQL SQL" Subject: Re: CREATE TABLE with foreign key and primary key In-reply-to: Message from "Paulo Roberto Siqueira" of Sun, 09 Jul 2000 22:49:14 -0300. Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 10 Jul 2000 10:16:30 +0100 From: "Oliver Elphick" X-Archive-Number: 200007/94 "Paulo Roberto Siqueira" wrote: >ufgvirtual=# create table matricula ( >ufgvirtual(# id_aluno char(15) references pessoa, >ufgvirtual(# id_curso int4 references curso_polo, >ufgvirtual(# id_polo int2 references curso_polo, >ufgvirtual(# local_prova varchar(50) not null, >ufgvirtual(# autorizado bool default 'f' not null, >ufgvirtual(# id_plano_pgto int2 references plano_pgto not null, >ufgvirtual(# data_matricula date default CURRENT_DATE not null, >ufgvirtual(# primary key(id_aluno,id_curso,id_polo)); ... >I have tables pessoa, curso, polo, curso_polo and matricula. Primary key in >curso_polo are id_curso (references curso) and id_polo (references polo). In >table matricula I want as primary key id_pessoa (references pessoa), >id_curso (references curso_polo) and id_polo (references curso_polo). You can't use REFERENCES on a column if the target primary key is made up of more than one column; you have to use a FOREIGN KEY table constraint: create table matricula ( id_aluno char(15) references pessoa, id_curso int4 not null, -- I assume you want id_polo int2 not null, -- not null here local_prova varchar(50) not null, autorizado bool default 'f' not null, id_plano_pgto int2 references plano_pgto not null, data_matricula date default CURRENT_DATE not null, primary key(id_aluno,id_curso,id_polo), FOREIGN KEY (id_curso, id_polo REFERENCES curso_polo (id_curso,id_polo)); -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight http://www.lfix.co.uk/oliver PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47 6B 7E 39 CC 56 E4 C1 47 GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "Delight thyself also in the LORD; and he shall give thee the desires of thine heart." Psalms 37:4