Key and key design

Because SQL depends on keys, we must take care to design and manage keys for our various objects. We must design a mapping from an object to the key that will be used to identify that object. One choice is to locate an attribute (or combination of attributes) that contains proper primary keys and cannot be changed. Another choice is to generate surrogate keys that cannot be changed; this allows all other attributes to be changed.

Most relational databases can generate surrogate keys for us. This is usually the best approach. For other unique attributes or candidate key attributes, we can define SQL indexes to improve the processing performance.

We must also consider the foreign key relationships among objects. There are several common design patterns: one-to-many, many-to-one, many-to-many, and optional one-to-one. We need to be aware of how SQL uses keys to implement these relationships and how SQL queries will be used to fill in the Python collections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset