Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Creating a table and a constraint
"Douglas Hawthorne" <douglashawthorne_at_yahoo.com.au> wrote in message
news:_YS8c.125222$Wa.105704_at_news-server.bigpond.net.au...
> "JellyBum" <......@......com> wrote in message
> news:vyS8c.200$X1.44_at_newsfe1-win...
> > Hi there, having a problem working out whats needed here.
> >
> > Im trying to create a table, this table is allowed to be null, but if
its
> > not then it must meet some other criteria. I know basically what im
doing
> > but cant geta few things im trying todo.
> > So far ive got:
> >
> > CREATE TABLE SystemUsers ( Staff_id char (3) CONSTRAINT pk_SU Primary
Key
> > ( Staff_id), Manager_id char (3)
> > now need it so, if a value has been entered into Manager_id it must
match
> a
> > value in Staff_id.
> >
> > Havent got a clue how to go about this? Cant find this specific thing in
> my
> > book either. Any help is apreciated
> >
> >
> Try the following:
>
> CREATE TABLE SystemUsers
> (
> Staff_id
> CHAR(3)
> CONSTRAINT systemusers_pk PRIMARY KEY,
> Manager_id
> CHAR(3),
> CONSTRAINT systemusers_mgr_id_fk
> FOREIGN KEY( manager_id )
> REFERENCES systemusers( staff_id )
> )
> ;
>
> What you want is a foreign key constraint pointing back to the same table.
> (A self-referential constraint).
>
> Douglas Hawthorne
>
>
i understand that, but how does a compare follow from that. Ive found that you cant do say name1=name2 in most versions of oracle, mine including. Received on Fri Mar 26 2004 - 12:27:53 CST
![]() |
![]() |