MySQL Forums
Forum List  »  Spanish

ayuda con integridad en MySQL
Posted by: edu ulles
Date: November 22, 2016 05:30AM

Buenos días! Estoy haciendo una base de datos en mySQL. Tengo dos tablas (soldados (id_soldado(PK), nombre_soldado, id_planeta, nivel_poder y id_categoria(FK)) y categorías (id_categoria (PK), nombre_categoria, nivel_poder_min, nivel_poder_max). Quiero aplicar un check que cada vez que añada un soldado me verifique que su id_categoria corresponda al valor correcto de la tabla categorías (que esté entre los parámetros de poder_min y poder_max correspondientes). Estoy aplicando este check:

alter table soldados
add constraint val_cat check (id_categoria =(
select categorias.id_categoria
from categorias, soldados
where soldados.nivel_poder>categorias.nivel_poder_min
and soldados.nivel_poder<categorias.nivel_poder_max))

Me podrían ayudar?

Muchas gracias!

Options: ReplyQuote


Subject
Views
Written By
Posted
ayuda con integridad en MySQL
1286
November 22, 2016 05:30AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.