tags:

views:

24

answers:

3

With Mysql tables like

table_main
    id
    firstname
    lastname

table_type
    id
    table_main_id
    table_type_id

table_type
    id
    typename   

can a single sql insert query be contructed to run once with

fields: firstname, lastname, typename
values: john,doe,mytypename
+1  A: 

Not that I'm aware of.

Flakron Bytyqi
A: 

Nope, but you can create a procedure and then call with it.

http://dev.mysql.com/doc/refman/5.1/en/create-procedure.html

Codler
+1  A: 

INSERT INTO table_name (firstname, lastname, typename) VALUES (john, doe, mytypename)

won't work because you're trying to insert into multiple tables at once.

My suggestion would be to make a stored procedure that takes arguments firstname, lastname, and typename and then does the proper inserts.

Siege898