|
About constraints in mysql... -
07-15-2008, 02:07 PM
Hi,
I've got some problems. How can I create constraint in phpmyadmin?
I've got two tables:
One table's called time, fields: Nick and dataone.
The other one is called stats, fields: datatwo, refs, clicks.
I want to create a constraint between dataone and datatwo. That is to say, a value in datatwo's field can only be inserted if this value already exists in dataone's field.
I haven't found the way to create it using phpmyadmin so I've tried to create it manually. The SQL query was:
ALTER TABLE `stats` ADD CONSTRAINT `statsFK`
FOREIGN KEY (`datatwo`)
REFERENCES `time` (`dataone`) ON DELETE CASCADE ON UPDATE CASCADE;
However, I've tried to insert some information in the stats' table, in order to blow up my DB, so I could know wether the constraint was right or not. I inserted a value in the datatwo field that didn't exist in the dataone field, and it worked well. Theorically, If the constraint was OK, I wouldn't be able to insert this kind of data.
Any help please? Where can I check the constraints in phpmyadmin? Because I want to review it but I dunno where it is...
Lots of thanks...!!
PS: By the way, the insert was:
INSERT INTO stats (data, refs, clicks) VALUES (NOW(), "asdasd", 5)
Last edited by samy4ever : 07-15-2008 at 02:16 PM.
|