Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Adding foreign keys after table creation?

Re: Adding foreign keys after table creation?

From: Sybrand Bakker <postmaster_at_sybrandb.demon.nl>
Date: Thu, 16 Dec 1999 07:06:51 +0100
Message-ID: <945324466.3579.0.pluto.d4ee154e@news.demon.nl>


The syntax is
alter table
add constraint <constraint name> foreign key (foreign key columns) references.

so in your case it should have been
alter table
add constraint cr_fk foreign key etc.
Note the fk will not be indexed automatically.

Why not buy Oracle 8 the complete reference of Kevin Loney, and the Oracle 8 DBA handbook, by Kevin Loney both published by Osborne.

Hth,
--
Sybrand Bakker, Oracle DBA
Doug O'Leary <dkoleary_at_mediaone.net> wrote in message news:MPG.12c218a637159e829896ed_at_nntp.ce.mediaone.net...
> Hi;
>
> I'm a complete newbie on Oracle and SQL. I got my copy of Oracle
> Personal Edition installed and working - at least the initial database is
> there and I'm able to play around with it.
>
> In order to learn, I've bought a book from Osborne called SQL, The
> Complete Reference. I tried the create table script that they have in
> the book and it's not working correctly due to the differences between
> what the book calls standard and Oracle's sql. If I can get the tables
> created, I can keep going with the book; however, I'm having difficulties
> working through Oracle's syntax for adding foreign keys after the table's
> been created.
>
> I've tried variations on the following:
>
> alter table customers
> modify cust_rep constraint foreign key cr_fk
> references salesreps;
>
> and
>
> alter table customers
> add constraint foreign key (cust_rep)
> references salesreps.
>
> Any tips on this particular problem would be greatly appreciated - also,
> any tips on sql books that lean towards Oracle would also be helpful.
>
> Thanks for your time.
>
> Doug O'Leary
> --
> ==============
> Douglas K. O'Leary
> Senior System Admin
> dkoleary_at_mediaone.net
> ==============
Received on Thu Dec 16 1999 - 00:06:51 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US