08 octubre 2009

How To Remove Foreign Keys In MySQL

Today i have a problem when trying to delete some tables that had circular reference (one was FK NULL) but the way is that you can not drop the table until you drop the foreign key reference for example:

ALTER TABLE myTable DROP FOREIGN KEY FK_nameDefinition;

You can check for more information with the ALTER TABLE instrucction on:
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

But browsing i have find a really cool solution to drop all foreign Keys or just get the names of this
foreign keys in the following blog:

http://www.justin-cook.com/wp/2006/05/09/how-to-remove-foreign-keys-in-mysql/

I have found it in a commet by "Jason" he recommends this cool query:

select concat('alter table ',table_schema,'.',table_name,' DROP FOREIGN KEY ',constraint_name,';') from information_schema.table_constraints;

Try out... see you... MySQL still Rules !!!

1 comentario:

noticias dijo...

guaaa!! me encanta el blog, siempre encuentro temas muy interesantes.

Publicar un comentario

Espero que realices comentarios que aporten, cualquier comentario fuera de lugar sera removido.

Acerca de mi

Mi foto

Ing. Informático / Computer Sci. Eng.
Líder de Proyectos de Desarrollo en  Síntesis S.A.

JAVA DEVELOPER, (JAVA EE WEB APPLICATIONS, SEAM, JBOSS, etc)
DOT NET DEVELOPER, FLASH (AS 2, 3.0)


Guitarrista / Guitar Player, @efsandino
http://bit.ly/efsandino

(Heavy Metal, Metal, Neo-Classical  Metal, metal, etc)

LinkedIN

Seguir en Facebook

Seguir por e-mail

Formulario de contacto

Nombre

Correo electrónico *

Mensaje *

Eduardo Sandino's Guitar

Eduardo Sandino's Guitar
Escucha las demos en guitarra de Eduardo F. Sandino, guitarrista boliviano de Santa Cruz.

Seguidores

Palestina Libre

Este blog apoya la causa por una Palestina libre. Basta del genocidio en Gaza.