I'm scripting out a fairly simple database so I can simply hand off a script to someone else for an application to use. I'm curious about where best practice/the community stand on this: When should you create your primary/foreign key constraints? Should you do it while you are creating the tables because of the continuity, or should you do it after the tables are created since it will be easier to script that way since you can create the tables in any order you wish? Are there any potential fatal flaws down the road with either pattern?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
I typically create the primary key constraint directly with the table:
I don't see any point in deferring that PK constraint to later (same also applies to
However, the FK constraint, I typically define those as separate