MySQL foreign keys support
#1

Heya there, I can't really understand the way foreign keys works in SAMP MySQL

If I have a parent table called users, and two child tables called toys and weapons
And I foreign them on the Auto Increase Primary column named ID (which exists in all of them)
If I insert data to the users table (ID Password and Name for example)
1. Would that automatically add a row with the given ID to the child tables ?
2. If I wipe one row from the users table, would that wipe the rows from the child tables aswell ?

Note: I put it to RESTRICT on both update and delete
Reply
#2

I'm wondering whether you linked them right because your description is kind of vague. Next to the auto-incrementing id column in the child tables you should also have a column that stores the id of the parent row in the parent table.

Rows never get added automatically. That's kind of the point.

If the cascade rules are set to restrict, you can't delete a user as long as they still have toys or weapons. You must remove everything belonging to that user from those tables first before you can delete the user himself. If the cascade rules are set to, well, cascade then everything belonging to that user in the child tables will automatically be wiped if the user is deleted.
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
I'm wondering whether you linked them right because your description is kind of vague. Next to the auto-incrementing id column in the child tables you should also have a column that stores the id of the parent row in the parent table.

Rows never get added automatically. That's kind of the point.

If the cascade rules are set to restrict, you can't delete a user as long as they still have toys or weapons. You must remove everything belonging to that user from those tables first before you can delete the user himself. If the cascade rules are set to, well, cascade then everything belonging to that user in the child tables will automatically be wiped if the user is deleted.
I tried it, I reviewed your guide and changed it from RESTRICT to CASCADE and tried deleting a user manually from the phpMyAdmin, nothing was deleted from the toys/weapons
So, can you explain me that "ID" type next to the A/I ? I don't really get that
Reply
#4

Anyone ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)