I got an answer to another question here:
It’s a great answer, but I am not understanding the bit about references. I can do SQL statements but I have never used references.
- What are they used for?
- How are they used?
- Give an example please
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The REFERENCES keyword is part of a foreign key constraint and it causes MySQL to require that the value(s) in the specified column(s) of the referencing table are also present in the specified column(s) of the referenced table.
This prevents foreign keys from referencing ids that do not exist or were deleted, and it can optionally prevent you from deleting rows whilst they are still referenced.
A specific example is if every employee must belong to a department then you can add a foreign key constraint from
employee.departmentidreferencingdepartment.id.Run the following code to create two test tables
tableaandtablebwhere the columna_idintablebreferences the primary key oftablea.tableais populated with a few rows.Now try these commands:
Important note: Both tables must be InnoDB tables or the constraint is ignored.