MySQL Forums
Forum List  »  Newbie

Inserting data into related tables
Posted by: Alin A
Date: September 06, 2022 11:02PM

Hello,

I am trying to understand how data has to be inserted into related tables.

Lets say I have a "User" table and a "Order" table with the following attributes:

CREATE TABLE User(
userID int PRIMARY KEY AUTO_INCREMENT,
userName varchar(70) UNIQUE NOT NULL,
passwd VARCHAR(70) NOT NULL,
INDEX(userID, userName))

CREATE TABLE Order(
orderID int PRIMARY KEY,
userReference, FOREIGN KEY(userReference) REFERENCES
User(userID),
userName1 VARCHAR(70) UNIQUE NOT NULL, FOREIGN KEY(userName1) REFERENCES
User(userName),
Product VARCHAR(70) NOT NULL,
INDEX(orderID, userName1))

How does a query, that wants to insert data into the "Order" table, has to look like?
To be more specific, how should the query look like to take over the data from the "User" table and relate to it?

Options: ReplyQuote


Subject
Written By
Posted
Inserting data into related tables
September 06, 2022 11:02PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.