Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem in deleting foreign key

Status
Not open for further replies.

JTan

Technical User
Oct 9, 2001
73
SG
Hi,

I am having difficulties in dropping a fk. The following is the table:

CREATE TABLE COMPANY (
COMPANY_ID VARCHAR(32) NOT NULL,
COMPANY_NAME VARCHAR(32) NOT NULL,
ADDRESS VARCHAR(32) NOT NULL,
LOCATION VARCHAR(32) NOT NULL,
PHONE CHAR(8) NOT NULL,
MODE VARCHAR(32) NOT NULL,
GROUP_ID VARCHAR(32) NOT NULL,
PRIMARY KEY (COMPANY_ID),
FOREIGN KEY(GROUP_ID) REFERENCES GRP(GRP_ID));

When I tried to delete the foreign key away, the error code:1025 will pop out, saying something like the table cannot be renamed.

May I know what is wrong?
 
The error goes like:

ERROR 1025(HY000) Error on rename of '.\vpg\company' to '.\vpg\#sql2-36c-1' (errno 152)
 
alter table company
drop foreign key group_id;
 
Starting from MySQL 4.0.13, InnoDB supports the use of ALTER TABLE to drop foreign keys:

ALTER TABLE yourtablename DROP FOREIGN KEY fk_symbol;

If the FOREIGN KEY clause included a CONSTRAINT name when you created the foreign key, you can refer to that name to drop the foreign key. (A constraint name can be given as of MySQL 4.0.18.) Otherwise, the fk_symbol value is internally generated by InnoDB when the foreign key is created. To find out the symbol when you want to drop a foreign key, use the SHOW CREATE TABLE statement. An example:


rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (next course starts May 8 2005)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top