If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Foreign key contraints

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-09, 20:54
mevets mevets is offline
Registered User
 
Join Date: Nov 2009
Posts: 1
Foreign key contraints

I have set up 3 tables that have foreign keys and primary keys. I want to delete these 3 tables but I cannot delete any of them because:
mysql> DROP TABLE POST, TOPIC, USER;
ERROR 1217 (23000): Cannot delete or update a parent row: a foreign key constraint fails

I get that certain tables cant be deleted because other tables have keys from that table, but if I try to delete all 3 tables in the equation then why do I still run into the same problem? How can I go about deleting these 3 tables.

mysql> DESCRIBE USER;
+------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+-------------+------+-----+---------+-------+
| U_ID | varchar(16) | NO | PRI | NULL | |
| U_PASSWORD | varchar(16) | YES | | NULL | |
| T_ID | int(11) | NO | MUL | NULL | |
+------------+-------------+------+-----+---------+-------+
3 rows in set (0.02 sec)

mysql> DESCRIBE TOPIC;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| T_ID | int(11) | NO | PRI | NULL | |
| POST_ID | int(11) | YES | MUL | NULL | |
| T_TEXT | text | YES | | NULL | |
| U_ID | varchar(16) | NO | MUL | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.01 sec)

mysql> DESCRIBE POST;
+-----------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+-------------+------+-----+---------+-------+
| POST_ID | int(11) | NO | PRI | NULL | |
| U_ID | varchar(16) | NO | | NULL | |
| POST_MESSAGE | text | YES | | NULL | |
| POST_SUBJECT | varchar(35) | YES | | NULL | |
| T_ID | int(11) | NO | | NULL | |
| POST_COMESAFTER | int(11) | YES | | NULL | |
+-----------------+-------------+------+-----+---------+-------+

ERD: http://img14.imageshack.us/img14/8690/41633351.gif
Youll see a PROFILE tables exists. It was there but it is the only one that would drop.
Reply With Quote
  #2 (permalink)  
Old 11-10-09, 21:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by mevets View Post
How can I go about deleting these 3 tables.
you gots to drop 'em in the correct order

i can't tell from your column names what the FKs are

instead of DESCRIBE, please do a SHOW CREATE TABLE for each table
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On