1

I have 2 tables, events and event_users:

Events

id      int  
type    int
date    date     
time    time     

Event_users

event_id    int
user_id     int
user_role   int
...

Events can have many event_users (one-to-many relationship).

When I insert more than one event in the Events table, the query is:

INSERT INTO events
    (type,date,time)
VALUES
    (1,12-02-14,08:15:00),
    (1,13-02-14,08:15:00),
    (1,14-02-14,08:15:00),
    (1,15-02-14,08:15:00)

But at the time I know the events table info, I also know some of the event_users table info.

So, because I need the events.id to write the event_users record, how can I insert the events and the event_users records in one query? The database is MySQL.

2
  • 1
    In MySQL, you cannot insert into 2 tables in one statement. You can though in many statements, inside one transaction. Apr 11, 2014 at 16:56
  • Thx @ypercube, could write down an example?
    – Luigi T.
    Apr 11, 2014 at 17:00

0

Browse other questions tagged or ask your own question.