UPI Study › Courses › Database Programming › Free lessons › Lesson 1.3 Free with a free account
Planning a Database Schema: Key Ideas and Steps
Database Programming · Chapter 1: Getting Started with Databases and SQL SetupSection 1.3 · lesson 3 of 768 min · free with a free account
Free preview
Create a free account to keep watching
It takes a minute and costs nothing. Your free account unlocks all of Chapter 1 and 3 more lessons of Database Programming.
Lesson complete
Earn the 3 college credits for Database Programming
Enrolling adds a quiz after each lesson, the graded work and the official transcript. Recommended for credit by NCCRS.
Next lesson: Querying Databases: Definitions and Essential Tools →← Varieties of Database Programs: Tools and Use CasesNext lesson: Querying Databases: Definitions and Essential Tools →
A free account plays all of Chapter 1 and 3 more lessons of Database Programming. Create a free account →
In this lesson
Turn requirements into entities, relationships, keys, and named tables.
- Gather requirements as both stored facts and questions the database must answer
- Identify entities, attributes, instances, and relationship cardinality
- Read an ER diagram with primary keys, foreign keys, and crow's-foot notation
- Resolve many-to-many relationships with a junction table and a fitting key
Free study notes
Get this lesson's notes by email
The key points and 4 practice questions with answers, in your inbox. One email, free.
One email. Unsubscribe in one click.
Transcript
Everything said in the video, section by section (1,020 words). Read along, or search it.
Opening Problem
Product One, Two, and Three Columns
Lantern Books wants a customer's purchase history. Leo could add product one, product two, and product three to the customer record. What happens when the customer buys a fourth product, or buys the same product on another day? A schema is the database blueprint: tables, columns, relationships, and constraints. Plan it from real questions, before storing real orders.
Design Route
From Requirements to Named Tables
Start by gathering requirements. Identify entities and attributes, then determine the relationships between those entities. Draw an entity-relationship diagram, add junction tables where needed, and translate the result into tables with consistent names. This is a route, rather than a one-way rule. A diagram can reveal a missing requirement, sending the team back to ask again.
Requirements
Stored Facts and Questions to Answer
Requirements describe both the data to store, and the questions the application must answer. Interview users and inspect their current forms. Maya needs each customer's name, city, and points. She also needs the products, quantities, and date for each order. Ask which orders belong to Asha, and what products each order contains. Those questions demand links among the records. Nouns suggest entities or attributes; verbs suggest relationships. Then test exceptions: can a customer place another order for the same product?
Entities
Entities, Attributes, and Instances
An entity is a thing or event we keep data about. Product is an entity; an order is another. An attribute describes that entity. Product name, price, and stock become columns in the products table. An instance is one particular occurrence. The reading lamp becomes a row, with its own product identifier. Each table needs a reliable primary key. It may be one column, or a combination whose values identify the row uniquely.
Attributes
Store a Birth Date, Not an Age
Keep each attribute focused on a fact the application needs. Separate name components when the work requires them; personal names do not all fit one pattern. Prefer a birth date to a stored age, when age can be calculated for the date of interest. Otherwise the saved age becomes stale. A publisher has its own name and city, so a publisher entity may be appropriate. This would extend our basic shop schema. Avoid making a new entity merely because a noun appears. Ask whether it has its own identity, facts, relationships, or repeated instances.
Cardinality
One-to-Many Customers and Orders
A relationship is an association, often expressed by a verb: a customer places an order. Cardinality describes allowed counts at each end. Can one customer place many orders? Yes. Can one order belong to several customers? Our shop rule says no. That makes customers to orders one-to-many. A different business rule could change the answer; the entity names alone do not decide it. One-to-one allows at most one on either side. Many-to-many allows multiple matches in both directions; each direction must be checked.
ER Diagrams
Crow's Feet, PK, and FK Markers
An entity-relationship diagram, or ER diagram, puts entities in rectangles, with their attributes inside. Lines connect related entities. Mark the primary key with PK, and a referencing foreign key with FK. Put the foreign key on the many side. The line says a customer places orders. A bar means one; a three-pronged crow's foot means many. Read both directions, and label the relationship with a verb. Optionality is another rule: zero allowed is different from at least one.
One-to-One
At Most One Card per Customer
Suppose the shop adds a customer card, allowing at most one current card per customer. That is a design extension. A foreign key in customer card links it to customers. By itself, that foreign key would still allow several cards for one customer. A uniqueness constraint on that customer reference enforces at most one card. A non-null constraint requires each card to identify a customer. Neither rule forces every customer to have a card. If membership requires one, the application and design must enforce that additional requirement.
Junction Tables
Order Items Resolve Many-to-Many
An order can contain many products, and a product can appear on many orders. Neither table should contain a growing list of repeated columns. Repeating all customer and product details on each pairing creates inconsistent copies. Store the pairing in a junction table, also called a bridge or association table. Our order items table holds order ID, product ID, and quantity. Quantity belongs to the relationship: how many of that product on that order. Now one order has many item rows, and one product has many item rows. The original many-to-many relationship becomes linked one-to-many relationships.
Choosing a Key
Order Pairs Versus Loan Events
For our order items, order ID plus product ID identifies a row. More copies of the same product increase its quantity. A borrowing system needs a different decision. The same member can borrow the same book on different dates. A loan identifier distinguishes those events, while loan date, due date, and return date describe each borrowing. Choose a junction name for its meaning: loan, booking, or order items. The identifier must match what one row represents.
Naming Conventions
Translating the Design into Tables
Entities become tables, attributes become columns, and instances become rows. Put references on the many side, and use junctions for many-to-many relationships. Our convention uses lowercase names with underscores, plural base tables, and descriptive columns. Match foreign-key names to their referenced keys. Prefer customer ID to a cryptic abbreviation; avoid spaces, unnecessary prefixes, reserved words, and a year embedded in the table name. Check every requirement, key, cardinality, reference, junction, and name. Finally, follow the keys to answer each question you wrote at the start.
Quick Check
Where Should the Display Date Live
An exhibition displays many works, and a work can join several exhibitions over time. Each showing has a display date to record. Where should that display date live? Read the choices, then pause, and decide.
Answer Explained
A Column on the Linking Row
A column on a row linking work and exhibition. The date describes that particular connection, rather than either endpoint alone. A single date on the work would collapse different exhibitions together. A single date on the exhibition would collapse different works together. If the same work returns to the same exhibition repeatedly, give each participation event a separate identifier. Check the repeat rule before choosing its key.
Key Takeaways
Test the Design by Following Keys
Start with stored facts and questions. The schema must support both. Identify entities, attributes, instances, and keys. Check every relationship in both directions. Draw the links, enforce the intended counts, and give many-to-many pairings their own rows. Use consistent names, then test the finished design by following keys to a real answer.
About Database Programming at UPI Study
Database Programming (Computer Science 381) is a self-paced online course of 76 video lessons in 12 chapters, from database applications, SQL setup, schema planning and normalization to keys and constraints, data types, filtering and sorting, joins, subqueries, views, indexes, ROLLUP and PIVOT, regular expressions and database security. It carries a NCCRS credit recommendation for 3 semester credits.
Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Enroll now → Course details Download the syllabus All Computer Science courses Every credit course with PRO →
Why take it here
Why students take Database Programming with UPI Study
Where the credit goes
Universities that work with NCCRS
Database Programming carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
Thomas Edison State UniversitySigned partner
University of the PeopleSigned partner
Charter Oak State CollegeSigned partner
Strayer UniversitySigned partner
Columbia Southern UniversitySigned partner
Indiana TechSigned partner
Penn StateWorks with NCCRS
Southern New Hampshire UniversityWorks with NCCRS
SUNYWorks with NCCRS
+many more cooperating universitiesFind my college →Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.
FAQ
Questions students ask us
About Planning a Database Schema: Key Ideas and Steps
What are the steps to design a database schema?
What is cardinality in an entity-relationship diagram?
How do you represent a many-to-many relationship in a relational database?
Should a database store a person's age or birth date?
About the Database Programming course
How many college credits is Database Programming?
How much does Database Programming cost and what is included?
Which universities accept UPI Study credits?
How long does Database Programming take?
How are the exams done?
How do my credits reach my college?
Ready for the full course? Earn 3 credits in Database Programming.
76 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.
Updated
3 credits · NCCRSEnroll →