Chapter 9. Complex and legacy schemas

 

In this chapter

  • Improving the SQL schema with custom DDL
  • Integrating with a legacy database
  • Mapping composite keys

In this chapter, we focus on the most important part of your system: the database schema, where your collection of integrity rules resides—the model of the real world that you’ve created. If your application can auction an item only once in the real world, your database schema should guarantee that. If an auction always has a starting price, your database model should include an appropriate constraint. If data satisfies all integrity rules, the data is consistent, a term you’ll meet again in section 11.1.

We also assume that consistent data is correct: everything the database states, either explicitly or implicitly, is true; everything else is false. If you want to know more about the theory behind this approach, look up the closed-world assumption (CWA).

9.1. Improving the database schema

9.1.1. Adding auxiliary database objects

9.1.2. SQL constraints

9.1.3. Creating indexes

9.2. Handling legacy keys

9.2.1. Mapping a natural primary key

9.2.2. Mapping a composite primary key

9.2.3. Foreign keys in composite primary keys

9.2.4. Foreign keys to composite primary keys

9.2.5. Foreign key referencing non-primary keys

9.3. Mapping properties to secondary tables

9.4. Summary

sitemap