Planning a Database Schema: Key Ideas and Steps, Explained

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

← 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 →

Earn 3 college credits for Database ProgrammingRecommended for credit by NCCRS · Computer Science 381 · self-paced · one payment, lifetime access

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.

Compare: Database Fundamentals vs Database Programming

Why take it here

Why students take Database Programming with UPI Study

Write the SQL behind every appDatabase Programming teaches SQL in MySQL and SQL Server side by side: designing and normalizing tables, keys and constraints, data types, inserting, updating and deleting rows, filtering, grouping, joins, subqueries, views, indexes, transactions, and protecting data from SQL injection. It suits computer science and information technology degrees.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

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.

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?
A typical route is to gather requirements, identify entities and attributes, determine relationships, draw an ER diagram, add junction tables, and translate the result into consistently named tables. Requirements cover both the data to store and the questions the application must answer. The route is not strictly one-way, since a diagram can reveal a missing requirement. Finish by following the keys to answer each original question.
What is cardinality in an entity-relationship diagram?
Cardinality describes how many instances can appear at each end of a relationship. If one customer can place many orders but each order belongs to one customer, the relationship is one-to-many. In crow's-foot notation, a bar means one and a three-pronged crow's foot means many. Business rules, not entity names, decide the cardinality, and optionality separately states whether zero is allowed.
How do you represent a many-to-many relationship in a relational database?
Use a junction table, also called a bridge or association table, that stores one row per pairing. For orders and products, an order_items table holds order_id, product_id, and quantity, turning one many-to-many relationship into two one-to-many relationships. Facts about the pairing itself, such as quantity, belong in the junction table. Its key must match what one row represents, so repeated events may need their own identifier.
Should a database store a person's age or birth date?
Store the birth date when age can be calculated from it, because a saved age becomes stale as time passes. This follows a broader schema rule: keep each attribute focused on a fact the application needs, and avoid values that drift out of date. Split names into parts when the work requires it, and create a new entity when a noun has its own identity, facts, or relationships, not merely because the noun appears.

About the Database Programming course

How many college credits is Database Programming?
Database Programming (Computer Science 381) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Database Programming cost and what is included?
$250, paid once, with lifetime access: all 76 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Database Programming take?
It is self-paced with no deadlines. The 76 lessons total about 11 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

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

Database Programming
3 credits · NCCRS
Enroll →