1. Home
  2. Explore
  3. Computer Science
  4. Database Design Fundamentals

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Database Design Fundamentals

Speaker 1Speaker 2

Database Design Fundamentals

19:32
0:00-19:32
  1. Corey

    Welcome back, everyone. Today we're introducing general relational database design. This is aimed at beginners, but the goal is to build skills you can apply across systems such as MySQL, SQL Server, Oracle, and other relational database management systems.

  2. Maria

    And the emphasis is design rather than immediately writing scripts. Before programming a database, you first think through what information must be stored, how it is connected, and how to structure it clearly. You can sketch those ideas on paper, a document, a whiteboard, or a database-design program.

  3. Corey

    Why does this matter? Almost every modern application uses a back-end database to store information. Websites, businesses, online stores, and personal projects all need reliable ways to store and retrieve data. A well-designed database can improve performance, protect data integrity, and make an application easier to maintain.

  4. Maria

    Let's start with the basic definition: a database is something that stores data. Data should be understood broadly as anything that can be stored or written down—customers, transactions, usernames, weather events, sales, or viewing history.

  5. Corey

    A website login is a simple example. When someone registers with a username, password, and email, those values are sent from the front end to the back-end database. Later, when the person logs in, the application checks the submitted values against the stored information.

  6. Maria

    The front end is what the user sees and interacts with. The back end is what happens behind the scenes, including the database and the server-side code that communicates with it. A front end is often used instead of letting ordinary users directly type database commands, which improves usability and security.

  7. Corey

    A database is more powerful than a simple spreadsheet once the information becomes complex. A spreadsheet may work for a small amount of data, but finding every employee who has worked for at least three years and missed fewer than three days would require manual checking. A database can run a query to find exactly those employees.

  8. Maria

    Databases also let us select only the information we need. Instead of exposing every employee column, a query might return just names and addresses. Different users can receive different views as well: an ordinary website user might see only their account information, while an administrator can access transactions, comments, or registration dates.

  9. Corey

    That selective access is a security feature. Access to a database does not automatically mean every user can update data, change the structure, or create views. Permissions can limit what a customer, advertiser, moderator, administrator, or company executive is allowed to see and do.

  10. Maria

    The word relational comes from mathematics, where a relation is a connection between sets. In database design, a relational database stores information in tables and connects related data. The term does not come directly from the everyday word relationship, although relational databases do contain relationships between tables.

  11. Corey

    The basic building blocks are entities and attributes. An entity is anything we store data about—a user, order, customer, employee, comment, or transaction. Attributes are the properties stored about that entity, such as a user's name, username, password, address, phone number, or email.

  12. Maria

    Suppose the entity type is user. Caleb and Billy can be two individual user entities. Username, name, and password are attribute types. Once we assign values—such as Caleb, Caleb Curry, and a password—we have specific attribute values for one entity.

  13. Corey

    In a table, attributes are represented by columns, and an individual entity's attribute values make up a row. A row is also called a tuple, record, or entry. A column is also called an attribute or field. A particular value is the information stored in one cell.

  14. Maria

    The table itself is another name for a relation, and older terminology may call it a file. The entity type describes what every row represents—for example, a user table should contain users. The specific entity is represented by an individual row.

  15. Corey

    A database management system, or DBMS, is software that manages stored data. It lets us run queries, search for values, update information, delete records, change how data is presented, and manage how data is stored. A relational database management system, or RDBMS, is a DBMS designed specifically for relational databases.

  16. Maria

    A query is a request to search or operate on data. For example, a DBMS could find transactions before a particular date or remove users who have not been active for a year. A view mechanism can present the same underlying data in different ways without changing the internal table structure.

  17. Corey

    Transactions are another important DBMS feature. A transaction is a multi-step operation that either completes fully or does not save at all. For example, transferring money may require deducting it from one account and adding it to another. If the server fails halfway through, the transaction can be canceled instead of leaving inconsistent data.

  18. Maria

    SQL, or Structured Query Language, is the general language used to communicate with relational databases. The exact syntax can vary between systems, but the general concepts remain similar. SQL has two major categories here: Data Definition Language, or DDL, and Data Manipulation Language, or DML.

  19. Corey

    DDL defines the database structure: creating tables, columns, and relationships. DML works with the values inside that structure by inserting, updating, deleting, and searching data. A CREATE command is an example of DDL, while UPDATE is an example of DML.

  20. Maria

    SQL also supports joins, which combine related data from separate tables into a new result. For example, a sales table might contain a user ID and purchased item, while a users table contains names. A join can return the person's name alongside the items they purchased without storing the name repeatedly in every sale row.

  21. Corey

    Naming conventions are patterns used consistently for tables and columns. One convention might use lowercase names, underscores instead of spaces, and matching names for related foreign-key columns. There is no single required convention, but consistency helps other people understand and maintain the database.

  22. Maria

    Database design is about building a structure that avoids data-integrity problems. Data integrity means the data is correct, current where appropriate, and properly connected. A database should avoid unexplained duplicates, outdated values, invalid relationships, and update anomalies.

  23. Corey

    There are three broad design levels. The conceptual schema describes how information is related without worrying about implementation details. The logical schema defines tables, columns, keys, and relationships. The physical schema addresses the actual database system, server, storage, access methods, security, and implementation.

  24. Maria

    Think of these as a continuum rather than completely separate steps. You begin with general ideas, move toward a logical structure, and then choose the physical implementation. Conceptually, a sale depends on a user because someone must make the purchase. Logically, you might create a users table and a sales table connected by a user ID.

  25. Corey

    A poor design might place a person's phone number, address, favorite colors, and every order into one giant table. If a person has two favorite colors, the person's name and phone number may have to be repeated in multiple rows. Updating one copy but not another creates inconsistent data.

  26. Maria

    The solution is usually to separate information into tables based on the entities involved. A user belongs in a user table, orders belong in an order table, and repeated or multi-valued information may need its own table. Good design reduces repetition and prevents one update from leaving conflicting copies behind.

  27. Corey

    There are three major forms of data integrity. Entity integrity ensures that each entity is unique, usually through a key. Referential integrity keeps relationships between tables valid. Domain integrity limits a column to acceptable values, such as requiring a phone-number column to contain an appropriate numeric format rather than the word cake.

  28. Maria

    A key identifies or connects data. A primary key uniquely identifies rows in its own table. A foreign key is a value in one table that references a primary key in another table. For example, a comment can contain a user ID that points to the user who posted it.

  29. Corey

    A primary key must be unique, must not be null, and should not change. A foreign key can sometimes be null if the relationship is optional, and its value can change when the relationship changes. A user might switch cars, for example, while the car IDs themselves remain stable.

  30. Maria

    A foreign-key constraint helps enforce referential integrity. Common actions include restricting an update or deletion, cascading the change to child rows, or setting the foreign-key value to null. If a user is deleted, cascading might remove that user's comments; restricting might prevent the deletion; setting null might preserve the comment but remove its user reference.

  31. Corey

    Those choices depend on the application. If a child record cannot exist without a parent, a foreign key may be required and marked not null. If an unassigned card or a class without an instructor must be allowed temporarily, the relationship may need to remain optional.

  32. Maria

    The three basic relationship types are one-to-one, one-to-many, and many-to-many. In a one-to-one relationship, each entity connects with at most one entity on the other side. A person and a supposed-unique social-security number are examples.

  33. Corey

    A one-to-one relationship is often stored as an attribute in the same table. A username may simply be a column in a user table. If the related entity has many additional attributes of its own, it may deserve a separate table—for example, a cardholder table connected to a card table.

  34. Maria

    A one-to-many relationship means one parent can be connected to many children, while each child connects back to one parent. A user can post many comments, but each individual comment belongs to one user. The foreign key goes on the many side, or child table, and points back to the parent table's primary key.

  35. Corey

    Many-to-many means both sides can have multiple connections. A student can take many classes, and each class can contain many students. You do not store this by making endless class columns in the student table or endless student columns in the class table.

  36. Maria

    Instead, you create an intermediary table, also called a junction table. It contains a student ID and a class ID. Each row represents one enrollment, and the two foreign keys connect back to the student and class tables. This converts the many-to-many relationship into two one-to-many relationships.

  37. Corey

    The intermediary row is the child of both parent tables. A particular student-and-class combination should not be duplicated. The same approach works for authors and books, users and videos, or professors and classes, depending on the application's rules.

  38. Maria

    The relationship type is not always determined by the nouns alone. A class and professor could be one-to-one if each class has exactly one professor and each professor teaches one class. It could be one-to-many if one professor teaches several classes, or many-to-many if classes can have multiple professors.

  39. Corey

    Keys can be described in several ways. A super key is any set of columns that makes every row unique. A candidate key is the smallest set of columns needed for uniqueness. If both username and email could uniquely identify an account, both may be candidate keys.

  40. Maria

    One candidate key is selected as the primary key. The others may be alternate keys and can still be indexed or constrained as unique. A natural key uses information already meaningful in the table, such as a username. A surrogate key is an added identifier, often an automatically generated number with no real-world meaning.

  41. Corey

    Natural keys avoid adding another column, but they can be difficult to find and may change as the application's meaning changes. Surrogate keys are stable and simple for relationships, but they add storage and can be less descriptive. A design should generally choose a consistent strategy rather than randomly mixing the two.

  42. Maria

    A simple key uses one column. A composite key uses multiple columns. Some people distinguish a compound key as a key whose component columns are themselves keys, such as the student ID and class ID in an enrollment table. Terminology can vary, so the important point is understanding whether uniqueness depends on one column or a combination.

  43. Corey

    Indexes improve lookup speed. Without an index, a database may scan rows one by one. With an index, it can locate relevant data much faster, similar to using a book's index or an alphabetized phone book. Primary keys are commonly indexed, and foreign-key or frequently searched columns may also benefit from indexes.

  44. Maria

    A clustered index organizes the actual data and is generally limited to one ordering. A nonclustered index is a separate structure that points to the data, so multiple nonclustered indexes can exist. Indexes speed up searches, where clauses, and joins, but they also require maintenance whenever the underlying data changes.

  45. Corey

    A lookup table is useful when a column has a fixed set of options, such as membership levels. Instead of repeating Gold, Silver, or Bronze in thousands of rows, store each option once with an ID and reference that ID from the members table. This reduces repetition, allows more information about each option, and makes updates easier.

  46. Maria

    Data types restrict what values a column can store. Broad categories include strings, numeric values, and dates. A fixed-length character type may suit a value such as a standardized code, while a variable-length character type suits text whose size differs. Larger text types can be used for comments or messages.

  47. Corey

    Numeric types include integers for whole numbers and decimal or floating-point types for values with fractional parts. Signed numbers can be positive or negative; unsigned numbers cannot be negative. Decimal and floating-point values are stored differently, so accuracy requirements matter when choosing between them.

  48. Maria

    Date-related types can represent a date, a time, or both. A timestamp records when something occurred, such as when an account was created or a row was inserted. The exact names and formats can vary between database systems, but the general categories are consistent.

  49. Corey

    Normalization is the process of improving a design by following normal forms. The first, second, and third normal forms are presented as a sequence: a design should satisfy first normal form before second, and second before third. A design in third normal form also satisfies the earlier forms.

  50. Maria

    First normal form focuses on atomic values. Each column should represent one kind of thing, and each cell should contain one value. Instead of storing a complete address in one column, you may separate street, city, state, and postal code if those parts need to be queried separately.

  51. Corey

    Similarly, do not store multiple email addresses in one cell separated by commas, and do not create a favorite-movies column that contains an unlimited list. Multiple values usually belong in a related table. Atomic does not mean splitting a word into individual letters; it means storing information at a useful, indivisible level.

  52. Maria

    Second normal form removes partial dependencies. This matters when the primary key contains multiple columns. A column should depend on the entire composite key, not just one part. In an author-book intermediary table, the author's name belongs with the author, the book's title belongs with the book, and an author-position value belongs in the intermediary table because it depends on both.

  53. Corey

    Third normal form removes transitive dependencies. A column should not depend on another non-key column that itself depends on the primary key. If a review table stores a star rating and also the meaning of that rating, the meaning depends on the rating, not directly on the review. Move rating definitions to a separate table and reference them with a foreign key.

  54. Maria

    A null value means that a field has no value. It is different from a value such as zero or an empty-looking text string. An anomaly is an error or unexpected result, such as one copy of a repeated address being updated while another copy remains old. Normalization and integrity rules are intended to prevent those anomalies.

  55. Corey

    Entity-relationship diagrams, often called ER diagrams or ER models, provide a standard way to sketch a database. You typically draw a box for each table, list its columns, and connect related tables. Crow's-foot notation can show whether a relationship is one or many, while optionality can show whether zero values are allowed.

  56. Maria

    For example, a line can represent a one-to-many relationship between cardholders and cards. A circle can indicate zero or optional participation, while a mark can indicate that at least one relationship is required. The exact notation can vary, but the purpose is to make table structure and cardinality visible before implementation.

  57. Corey

    Now let's return to joins. A join is a data-manipulation operation that combines normalized data into a more readable result. The database may correctly store a user ID in a comments table, but a join can display the user's name beside the comment.

  58. Maria

    An inner join returns rows that match in both tables. If customers and cards are joined by customer ID, customers without cards and cards without customers are excluded from the result. The join condition identifies the matching columns, usually a primary-key and foreign-key pair.

  59. Corey

    A left outer join keeps every row from the left table and includes matching rows from the right table. A right outer join does the reverse. In practice, a right join can often be rewritten as a left join by switching the table order, which many designers prefer for consistency.

  60. Maria

    With three or more tables, joins are applied step by step. You can join users to comments and then join that result to videos. Each additional inner join can reduce the result to rows that match all required conditions, while outer joins preserve rows from the selected outer side.

  61. Corey

    Aliases give tables or columns temporary, readable names in a query. A table might be shortened from user to u, and then a reference can be written as u.user_id. A column alias can rename an output column, such as displaying a technical name as First Name.

  62. Maria

    Aliases are essential in a self-join, where a table is joined to itself. For a referral system, one user row can contain the ID of the user who referred them. You can treat one reference as the referred user and the other as the referring user, then join the table to itself using two different aliases.

  63. Corey

    The larger lesson is that good database design balances structure and usability. Internally, data should be separated to reduce repetition, preserve integrity, and support efficient updates. Externally, joins and views can present that same information in a clear format for users, applications, and analysts.

  64. Maria

    So the overall workflow is: understand the application, identify entities and attributes, define relationships, choose keys, separate tables appropriately, enforce domains and referential integrity, normalize the design, consider indexes and data types, and plan the joins or views that users will need.

  65. Corey

    And because these are general design ideas, they are not limited to one product. The syntax for SQL, constraints, data types, indexes, views, and joins may differ between systems, but the underlying reasoning carries across relational database platforms.

  66. Maria

    That gives us the foundation: databases store data; tables organize entities and attributes; keys identify and connect rows; relationships describe how entities interact; normalization reduces anomalies; integrity rules protect correctness; indexes improve access; and joins turn structured storage into useful results.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent