database - Mysql : I want to create a trigger which will insert data into user access permission table based on employee table and categories table -


i have 3 tables :- category ,employee , user_access_permission . want create trigger fire when new category added , insert values in user_access_permission each employee id .default value user_access 0.

category table :-

create table if not exists `categories` (   `category_id` int(11) not null auto_increment,   `category_name` varchar(100) not null,   `section_id` int(11) not null,   unique key `category_id` (`category_id`),   unique key `category_name` (`category_name`) ) engine=innodb  default charset=latin1 auto_increment=1 ; 

employee table :-

create table if not exists `employee` (   `employee_id` int(11) not null auto_increment,   `emp_pass` varchar(50) not null,   `email` varchar(100) not null,    primary key (`employee_id`),   unique key `email_unique` (`email`)  ) engine=innodb  default charset=utf8 comment=' ' auto_increment=1; 

user access permission table :-

create table if not exists `user_access_permission` (   `uap_id` int(10) not null auto_increment,   `section_id` int(10) not null,   `category_id` int(10) not null,   `employee_id` int(10) not null,   `access_level` int(10) not null default '0',   primary key (`uap_id`) ) engine=innodb  default charset=latin1 auto_increment=1; 

i writing trigger :-

create trigger update_permssion_on_add_category  after insert    on categories each row     insert user_access_permission(section_id,category_id,employee_id,access_level) select(new.section_id,new.category_id,employee_id,0) employee 

but don't things right. please help

you have

select(new.section_id,new.category_id,employee_id,0) employee 

but section_id , category_id come category table.

i suggest changing 'from category' problem employee_id number from? it's not anywhere in original insert statement category table. unless decide have default value every time trigger fired.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -