문제

is it possible to insert values into different tables using mysql qyery??

올바른 솔루션이 없습니다

다른 팁

Yes, but you need to create custom functions that insert values to other tables as a side-effect.

The basic idea is that you want to insert the result of the function into the table you are inserting other data

insert into table (resulting_value) values (my_function(parameters))

You can read more about stored functions from the MySQL documentation

There is no one query that can do that, but assuming you're working with PHP, you can get the primary key of the last inserted row using mysql_insert_id() and then you can construct the second query with that field.

you could maybe do it using a trigger(s) (i.e. you issue one SQL insert statement and subsequent inserts are carried out in the database), as long as

  1. your subsequent insert values can be derived from the value of the preceding insert
  2. you don't mind living with the problems that such an approach might give rise to (unclear error messages when a trigger fails, silent insert failures, performance issues etc.etc.)

The Insert command just allows one target table for data to be inserted...

INSERT INTO target_table () VALUES();

A good workaround can be done while using Triggers.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top