If I’m going to write a whole SQL script to create a database with tables (that has foreign keys) should I write the dependent tables first?
Share
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.
You have some options:
ALTER TABLEto add the Foreign Keys.When you create such DBs you (more often than not) seed the tables with data as well.
Depending on how much data you insert, you may want to make a decision to either INSERT data first, or to enforce RI first. If you have small tables, the RI checks don’t consume too many resources. If you have large tables, then you may want to first insert the data and then implement the RI – that way the check is not done one row at a time, but at one time for all rows. Since you’re seeding the tables, you know your data – presumably you’ll do clean inserts so as to not fail the downstream RI check.