Inserting and updating a new record in multiple tables joined by a foreign key?

Hi all

A newby database question.

I am moving along with Wappler and now comfortable with working with a single mysql table and now I want to be able to insert a new record in a table and also a foreign key associated table.

For example:

I have a “User” table with a primary key ‘userid’ and fk = ‘accountid’ which is attached to an “Account” table with the primary key being “accountid”. Now I assume I have this around the correct way (Account table will be attached to other tables). An account can have many user but users belong to one account.

User:

userid - pk
first name
last name
some other stuff
accountid - fk

Account:

accountid - pk
account type
other stuff

My question:

So a user signs up and I create a new “User” record and I also want to create a new “Account” record for the user and relate it to a new account record.

It is easy enough to insert a new record in the “User” table, but what it the best way to insert the associated account record.

My thinking is I would need to create an account record first and then create the “User” record and some how associate using the ‘accountid’ - fk

Can anyone shed a process or tutorial where you insert a record into multiple tables that share a relationship like this.

Once I see it in the Wappler process I can work it out from there?

Thanks again!

Community Page
Last updated: