dbTalk Databases Forums  

Newbie question

comp.databases.oracle comp.databases.oracle


Discuss Newbie question in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ERD
 
Posts: n/a

Default Newbie question - 09-30-2004 , 03:49 PM






New to Oracle and having an apparent RI problem in SQL PLus.

Ran a script to create some tables. When I began to drop them (this is
for a class) one would not drop citing an RI constraint.

I have a problem with a table in SQL Plus.

When I try to drop this table (Product), I get this

SQL> drop table Product;
drop table Product
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by
foreign keys

I thought I understood RI, but in this case......there
are no other tables still existing. I went through the script that
created the tables and checked every reference to this one.

Is there a command I can issue to determine what its
talking about?

A describe yields this

SQL> describe Product
Name Null? Type
----------------------------------------- --------
PROD_NUM NOT NULL NUMBER
ARTISTS_NAME VARCHAR2(40)
PROD_NAME VARCHAR2(40)
PROD_TYPE VARCHAR2(10)
YEAR_REL DATE

Any thoughts?

Thanks in advance.

Reply With Quote
  #2  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: Newbie question - 09-30-2004 , 04:01 PM







"ERD" <erd (AT) nospam (DOT) net> wrote

Quote:
New to Oracle and having an apparent RI problem in SQL PLus.

Ran a script to create some tables. When I began to drop them (this is
for a class) one would not drop citing an RI constraint.

I have a problem with a table in SQL Plus.

When I try to drop this table (Product), I get this

SQL> drop table Product;
drop table Product
*
ERROR at line 1:
ORA-02449: unique/primary keys in table referenced by
foreign keys

I thought I understood RI, but in this case......there
are no other tables still existing. I went through the script that
created the tables and checked every reference to this one.

Is there a command I can issue to determine what its
talking about?

A describe yields this

SQL> describe Product
Name Null? Type
----------------------------------------- --------
PROD_NUM NOT NULL NUMBER
ARTISTS_NAME VARCHAR2(40)
PROD_NAME VARCHAR2(40)
PROD_TYPE VARCHAR2(10)
YEAR_REL DATE

Any thoughts?

Thanks in advance.
SELECT *
FROM all_constraints
WHERE (r_owner, r_constraint_name) IN (SELECT owner
,constraint_name
FROM user_constraints
WHERE constraint_type = 'P'
AND table_name = 'PRODUCT')

perhaps a table in another schema has an FK reference

you can always do a 'drop table xxx cascade constraints'

++ mcs




Reply With Quote
  #3  
Old   
ERD
 
Posts: n/a

Default Re: Newbie question - 09-30-2004 , 04:10 PM



Yes I finally figured out the cascade constraints.
Thanks for that select statement.

Question: does this imply that the RI in the relationship was not defined
correctly?



"Mark C. Stock" <mcstockX@Xenquery .com> wrote in
news:tvGdnX_CI_Oj6cHcRVn-sA (AT) comcast (DOT) com:

Quote:
"ERD" <erd (AT) nospam (DOT) net> wrote in message
news:Xns9574AB194D277glnospamnet (AT) 216 (DOT) 196.97.131...
| New to Oracle and having an apparent RI problem in SQL PLus.
|
| Ran a script to create some tables. When I began to drop them (this is
| for a class) one would not drop citing an RI constraint.
|
| I have a problem with a table in SQL Plus.
|
| When I try to drop this table (Product), I get this
|
| SQL> drop table Product;
| drop table Product
| *
| ERROR at line 1:
| ORA-02449: unique/primary keys in table referenced by
| foreign keys
|
| I thought I understood RI, but in this case......there
| are no other tables still existing. I went through the script that
| created the tables and checked every reference to this one.
|
| Is there a command I can issue to determine what its
| talking about?
|
| A describe yields this
|
| SQL> describe Product
| Name Null? Type
| ----------------------------------------- --------
| PROD_NUM NOT NULL NUMBER
| ARTISTS_NAME VARCHAR2(40)
| PROD_NAME VARCHAR2(40)
| PROD_TYPE VARCHAR2(10)
| YEAR_REL DATE
|
| Any thoughts?
|
| Thanks in advance.

SELECT *
FROM all_constraints
WHERE (r_owner, r_constraint_name) IN (SELECT owner
,constraint_name
FROM user_constraints
WHERE constraint_type = 'P'
AND table_name = 'PRODUCT')

perhaps a table in another schema has an FK reference

you can always do a 'drop table xxx cascade constraints'

++ mcs





Reply With Quote
  #4  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: Newbie question - 09-30-2004 , 04:28 PM




"ERD" <erd (AT) nospam (DOT) net> wrote

Quote:
Yes I finally figured out the cascade constraints.
Thanks for that select statement.

Question: does this imply that the RI in the relationship was not defined
correctly?



not at all -- its not abnormal to need to use cascade constraints option if
FKs still exist, and its not abnormal if a table in another schema has FK
constraints

did you find out which table has the FK before you used the 'cascade
constraints' option?

++ mcs




Reply With Quote
  #5  
Old   
ERD
 
Posts: n/a

Default Re: Newbie question - 09-30-2004 , 05:12 PM



I did through re-running the original scripts. Many thanks



I ran a SELECT object_name FROM user_objects; and came up with, among
other things,
Quote:
did you find out which table has the FK before you used the 'cascade
constraints' option?

++ mcs





Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.