Let the Database Enforce It
A constraint holds regardless of which code is writing. Your application validates to produce a helpful message. The constraint is what makes the rule true, including when a migration, a script, an admin action or a future colleague is the one writing.
From the SQL course: NOT NULL, UNIQUE, REFERENCES, CHECK, and a real primary key on every table.
Index what you filter and join on, once you know what that is. Not before: an index added on a guess is a cost with no proven benefit, and somebody has to maintain it.
The routine is unchanged from the SQL course. Run the plan, find the scan, add the index, run the plan again and confirm it changed. The last step is the one people skip.
Mark this lesson complete
Signed in, your progress follows you to every device.