I heard that SQL is faster if table relationships are defined.
Is this true?
Or maybe it’s slower, I would like to know.
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.
My guess is that you’re talking about foreign keys. This is also known as referential integrity, and is one kind of constraint. Foreign keys are not the only kinds of constraints–you can have unique and check constraints, as well. Anyway, referential integrity is slightly slower for
inserts, and not faster at all forselects.The reason is that it has to check
inserted values to ensure that they exist in the other table.If you want to improve the performance of
selectqueries, you want to put indices on columns that you’ll be joining and filter on. However, indices do come at a cost, as they slow downinserts,updates, anddeletes, because the indices have to update every time the table changes like that.So, if your table is high volume
insert/update, don’t add too many indices. If your table is predominantlyselect, use indices where you can. The Database Engine Tuning Advisor can help you define those indices for some of your most common queries, as well.Ensure that you use the Query Execution Plan when running your queries (Ctrl + L in SSMS) so that you can see what SQL Server is doing. You want as many
seeks as possible, as that means that it’s able to use an index most efficiently!