Dynamic data entry in 2 tables

Asked

Viewed 94 times

0

Good afternoon, everyone.

I have the following situation:

In a vehicle registration module need to dynamically register and at once a vehicle followed by all its models and group, and a vehicle can have N models and be registered in N groups, which is the best way for me to make such registration?

That is, the user enters the vehicle registration module and clicks on REGISTER VEHICLE then opens a registration screen and within this registration he informs the name of the vehicle and then on the same screen click on add model, and register the model, photo of this model and insert this model within a certain group, then he clicks ok next and this data is there on stand by (not yet registered in the comic) then after this the user has the option to click again on register model and register another model with other photos and in another group and then click ok and this data is also on stand by.

Now comes the hard part, below this form has a sign up button, when I click there will register the vehicle_id, vehicle_title and vehicle_name in the table VEHICLE and the vehicle_model, vehicle_cover, vehicle_group in the table VEICULO_MODELO.

The question is, what is the best way for me to accomplish this? Can I simultaneously write data from 1 SINGLE FORM to 2 TABLES IN THE BD? Remembering that within this FORM there can be 1 or more model array, that is, if I register a vehicle and within the register 2 more models then the vehicle data will be recorded in the vehicle table and 2 model records with different id in the vehicle table

2 answers

0

It will store in an auxiliary table when it finalizes the entries ai passes from the auxiliary table to the main table or stores all the data in session thus entering in the table when it finishes the entries

  • Weidson, but if I store in the session at the end of the accounts I will have to take this stored data and divide it by sending each input to its proper table...Have some article or tag to help me research how I do this?

0

Herman,

In relational databases you cannot insert more than one table at a time. What you need to do is perform your Inserts using a transaction after all the transaction will avoid inconsistencies in case any error occurs.

Let’s say you will insert the GOL car and it will have 3 models [a, b, c]. You will start a transaction-> insert the car gol -> insert the templates -> close the transaction. Ah but if there is an error in writing model B? Quiet, the bank will undo all changes related to that transaction in question.

BEGIN TRAN T1;
INSERT table1 ...;
SELECT table1 ...;
INSERT table2 ...;

COMMIT TRAN T1;

Source

  • Opa Èrik, I’ll read the article you indicated...and then when I have enough reputation points I’ll come back here to mark your response as positive.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.