1 / 4

Designing a SQL Database for a Hockey League with Constraints and Dependencies

This example illustrates the creation of a SQL database for managing a hockey league, including details about rinks, teams, and players. The database employs tables for Rink, Team, and Player, adhering to BCNF principles, with specific foreign key relationships. Players wearing uniform number 9 are constrained to being goalies. A potential dependency arises when cities are linked to rink capacities, necessitating joins for validation. The trade-off between performance and consistency highlights the challenges of managing database constraints. Understanding keys and constraints in SQL is essential for efficient database design.

coral
Télécharger la présentation

Designing a SQL Database for a Hockey League with Constraints and Dependencies

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SQL Tables and Constraints Example

  2. The Database • A hockey league with rinks, teams, and players: • Rink (name, phone, capacity) • Team (tname, city, color, wins, losses, tie, rname FK references Rink(name)) • Player (id, name, num, pos, tname, tcity, FK (tname, tcity) references Team (tname, city)) • All relations are in BCNF • The only FDs are PKall other fields • Constraint: All players with uniform number 9 must be goalies.

  3. Unpreserved Dependencies • Suppose the users now decide that all rinks in the same city have the same capacity: • city  capacity • While trying to remain calm, you realize that: • This FD doesn’t exist in any single relation, so a join is required to check it each time we add or change a capacity value. • The tradeoff: • Expensive to check, but • may not be checked often enough to justify creating a dependency-preserving decomposition.

  4. Summary • Keys can be specified: • With the attribute, for single-field keys • At end of “create table” statement (all keys) • In a separate “alter table” statements (all keys) • “Check” constraints very useful • SQL Server: can only involve one relation • SQL Standard: more general • Triggers, assertions for IC (FD) enforcement • SQL Server doesn’t support assertions • Must be careful, in general, with triggers

More Related