I’m new in sql. I have doubt. Let’s say that I have two tables. One is called user and the other order.
User
User_Id - name - email
Order
Order_id - product - User_id
What query should I use to insert a new order in the order table with the User_id field related to the User_id from the user table(an existing user)
Eg:
Order_id - product - User_id
1a - plate - 1
2a - car - 3
3a - bike - 1
If you have
nameoremailof the user, you can try this. If USER has a composite primary key onuser_idandnamecolumns, it will work without any issues. Better to keep foreign key relationship on user_id column ofORDERalso.Example has NAME column, you can try with email column also.
EDIT:
I have worked on Oracle sql only. After your comment, found this link.
http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
If you have defined AUTO_INCREMENT on order_id column, you don’t need to pass value.