Dropping an unnamed constraint

Hi everyone. I need to drop a foreign key constraint from a table (or
add an "ON DELETE SET DEFAULT") but the constraint is unnamed. Is
there anyway to do that? I looked online but didn't find anything.

-Brandon
bcr07548 [ Mi, 13 September 2006 01:48 ] [ ID #1464809 ]

Re: Dropping an unnamed constraint

Brandon wrote:
> Hi everyone. I need to drop a foreign key constraint from a table (or
> add an "ON DELETE SET DEFAULT") but the constraint is unnamed. Is
> there anyway to do that? I looked online but didn't find anything.

Use "SHOW CREATE TABLE tablename". It'll show you the constraint name,
which was generated automatically by MySQL when you declared the foreign
key.

Example:

create table prim (i int primary key);
create table fore (i int, foreign key (i) references prim(i));

show create table fore;

CREATE TABLE `fore` (
`i` int(11) default NULL,
KEY `i` (`i`),
CONSTRAINT `fore_ibfk_1` FOREIGN KEY (`i`) REFERENCES `prim` (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

Regards,
Bill K.
Bill Karwin [ Mi, 13 September 2006 19:16 ] [ ID #1464811 ]

Re: Dropping an unnamed constraint

> > Hi everyone. I need to drop a foreign key constraint from a table (or
> > add an "ON DELETE SET DEFAULT") but the constraint is unnamed. Is
> > there anyway to do that? I looked online but didn't find anything.
>
> Use "SHOW CREATE TABLE tablename". It'll show you the constraint name,
> which was generated automatically by MySQL when you declared the foreign
> key.
>
> <SNIP>

Actually, I tried that and it still didn't show an identifier.
bcr07548 [ So, 17 September 2006 03:52 ] [ ID #1469093 ]

Re: Dropping an unnamed constraint

Brandon wrote:
>> Use "SHOW CREATE TABLE tablename". It'll show you the constraint name,
>
> Actually, I tried that and it still didn't show an identifier.

This may be dependent on the version of MySQL you use. I tested the
example I gave, using MySQL 5.0.24. What version are you using?

Regards,
Bill K.
Bill Karwin [ So, 17 September 2006 18:56 ] [ ID #1469097 ]
Datenbanken » mailing.database.mysql » Dropping an unnamed constraint

Vorheriges Thema: root user without privileges?
Nächstes Thema: Creating FUNCTIONS/PROCEEDURES