oracle - Trigger Before Insert on multiple tables -
i new triggers , pl/sql, question 1 of design.
i creating set of tables represent ticket purchases. there 3 types of tickets:
- ticket #1: price, quantity, time
- ticket #2: price, quantity, time, seating, refundable
- ticket #3: price, quantity, time, food , drink
so have created 3 tables: (i believe called, normalizing):
table1 has columns price, quantity , time
table2 has seating , refundable
table3 has food , drink
i have inserted primary key column table1 , using foreign keys in table2 , table3 point table1's pk.
the plan: when user purchases ticket, insert record appropriate table(s). instance, if user purchases:
ticket #1, insert record table1
ticket #2, insert record table1 , table2
ticket #3, insert record table1 , table3
the problem: how can receive data ticket not of type 1, , split parameters insert separate tables. instance, when try create trigger table2, trigger can receive parameters match table2 columns has. how can receive data table1?
an example of complete purchase of ticket type 2.
user purchases ticket online -> web form stuff happends... -> dao sends 1 insert command database -> trigger table2 kicks off , validates info table1 , table2.
thanks!
you can design in way want, given there's not difference between ticket types i'd have single table:
create table ticket (id_ticket number constraint pk_ticket primary key using index, ticket_type number not null constraint ticket_ck1 check(ticket_type in (1, 2, 3)), price number not null, quantity number not null, departure_time date not null, seating number constraint ticket_ck2 check(1 = case ticket_type when 1 case when seating null 1 else 0 end when 2 case when seating null 0 else 1 end when 3 case when seating null 1 else 0 end end), refundable_indc char(1) not null constraint ticket_ck3 check(refundable_indc = case ticket_type when 1 'n' when 2 'y' when 3 'n' end), food char(1) not null constraint ticket_ck4 check(food = case ticket_type when 1 'n' when 2 'n' when 3 'y' end), drink char(1) not null constraint ticket_ck5 check(drink = case ticket_type when 1 'n' when 2 'n' when 3 'y' end)); here check constraints used ensure appropriate fields filled in, based on ticket type.
best of luck.
Comments
Post a Comment