Look at my table design below. It is a table that shows the roles of users.
CREATE TABLE userrole
(userid
bigint(20) unsigned NOT NULL,roleid
int(10) unsigned NOT NULL,
PRIMARY KEY (userid
,roleid
),
KEY fk_userrole_roleid
(roleid
),
CONSTRAINT fk_userrole_userid
FOREIGN KEY (userid
) REFERENCES user
(user_id
) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT fk_userrole_roleid
FOREIGN KEY (roleid
) REFERENCES role
(role_id
) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB
Is it better for me to use the foreign keys or not ?
Do foreign keys perform faster than no foreign keys ?
Is it faster using ON DELETE/UPDATE CASCADE than querying it manually ?
When shouldn't I use foreign keys and When I should ?