SELECT INTO or Stored Procedure?
- by Kerry
Would this be better as a stored procedure or leave it as is?
INSERT INTO `user_permissions`
( `user_id`, `object_id`, `type`, `view`, `add`, `edit`, `delete`, `admin`, `updated_by_user_id` )
SELECT `user_id`, $object_id, '$type', 1, 1, 1, 1, 1, $user_id
FROM `user_permissions`
WHERE `object_id` = $object_id_2 AND `type` = '$type_2' AND `admin` = 1
You can think of this with different objects, lets say you have groups and subgroups. If someone creates a subgroup, it is making everyone who had access to the parent group now also have access to the subgroup.
I've never made a stored procedure before, but this looks like it might be time. This call be probably be called very often.
Should I be creating a procedure or will the performance be insignificant?