Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
samy4ever is on a distinguished road
 
Posts: 6
Join Date: May 2008
Default 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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.6.9
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0
vBulletin Skin developed by: vBStyles.com