Simple question.
If i had a table users which contains columns like username, password, and an auto incrementing id which is the primary key.
And another table called names which contains first_name, middle_name, last_name and a foreign key called user_id which references the id in the users table.
Do I have to insert a value to that foreign key? Or SQL will automatically copy the value of the id in the users table?
Another follow up question, What is the data type of the user_id field in the names table?
Yes, you will have to insert the foreign key. When you insert a record into the names table, SQL will not automatically be able to know which user the names record is referring to.
As user_id is referring to an id field that is auto-incrementing it is most likely going to be an integer field.