I have two tables in a database, Products and ProductKeys.
Products columns:
ProductID(PK)ProductName
ProductKeys columns:
ID(PK)ProductKeyProductID(FK)Price
I am trying to insert a new ProductKey.
Let's say I have a product with ProductID = 1 and ProductName = 'test'
Insert into ProductKeys(ProductKey, ProductID, Price)
select 'testkey', 1, 4
This of course works. But what if I want to insert a new ProductKey based on a product name and the ProductID to be set automatically based on the ProductName.
I hope you understand my issue. Thank you in advance people! Cheers.
EDIT: To insert in that table i must provide all fields a value , but what if I do not know the value of the ProductID and I know the ProductName, so I can insert a ProductKey based on a ProductName not a ProductID.
Sorry for the mess guys , new to SQL.