Re: Foreign Key Problems

From: Sanjeev.Agrawal <sanju_at_churchill.ColumbiaSC.NCR.COM>
Date: Wed, 10 Aug 1994 13:26:49 GMT
Message-ID: <CuBMop.7vs_at_ncrcae.ColumbiaSC.NCR.COM>


In article <ggrieffCu64CD.7KM_at_netcom.com> ggrieff_at_netcom.com (Greg Grieff) writes:
>I must be missing something...please help?!
>
> I would like to create two tables, a parent table and a child table
>such that the child table will only accept rows for insert if there is a
>valid parent record that it references. Basically the text book primary
>key - foreign key relationship. Following is my SQL code to create the
>two tables.
>
>create table a (docid number(9) not null primary key,
> lname char(8),
> fname char(8))
>/
>
>create table b (imgid number(9) not null primary key,
> docid number(9) not null references a (docid) constraint
>docid_fk,
> filename char(8),
> sideid char(3))
>/

I am not sure whether this syntax works on your machine. I guess constraint name should come before the constraint definition. try using this:

create table b (imgid number(9) not null primary key,

                docid number(9) not null constraint docid_fk references a (docid) ,
                filename char(8),
                sideid char(3))

/

Hope it helps,

sanjeev
>
> Now when I attempt to insert a record into b it will allow be to
>regardless of whether a valid parent record in a exists. What am I
>missing? Any help would be greatly appreciated.
>
>Thanks in advance,
>-Greg
>
>-------------------------------------------------------------------------
>| Greg Grieff ggrieff_at_netcom.com | "Dream, Design, Develop, Debug, |
>| Head of Engineering | Deliver... Not necessarily in |
>| Micrographic Specialties Inc. | that order." |
>-------------------------------------------------------------------------
>

-- 
*-------------------------------------------------------------------------*
|  Sanjeev Kumar Agrawal          Phone: (803) 939-6835(W) / 791-9048 (H) |
|               Experience is the name we give to our mistakes !          |
*-------------------------------------------------------------------------*
Received on Wed Aug 10 1994 - 15:26:49 CEST

Original text of this message