Issue
Have this SQL.
CREATE TABLE `accounts` (
`account_id` int(3) NOT NULL,
`username` varchar(36) NOT NULL,
`password` varchar(36) NOT NULL,
`email` varchar(60) NOT NULL,
`access_level` int(1) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `normal_profile` (
`normal_profileid` int(11) NOT NULL,
`first_name` varchar(64) NOT NULL,
`middle_name` varchar(64) NOT NULL,
`last_name` varchar(64) NOT NULL,
`age` int(2) NOT NULL,
`gender` varchar(6) NOT NULL,
`account_id` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `normal_profile`
ADD CONSTRAINT `normal_profile_ibfk_1` FOREIGN KEY (`account_id`) REFERENCES `accounts` (`account_id`);
The above is how i set constraints.
Whenever i insert something on to my accounts table, do i also have to query an insert into the normal_profile table? or can i automatically make it so that the DB itself will just add a row into normal_profile where account_id = accounts.account_id?
I have a vague memory of an on insert constraint or maybe im mistaken?
Solution
try this syntax
delimiter #
CREATE TRIGGER after_accounts
AFTER insert ON accounts
FOR EACH ROW
BEGIN
-- your insert query
end#
delimiter ;
Answered By - Ehsan Ilahi
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.