# Entity Relationship Diagrams and Creating Tables
# Understanding Entity Relationship Diagrams
Entity Relationship Diagrams (ERDs) are a fundamental part of database design and architecture. They provide a visual representation of the data and how entities within a database relate to each other. Using ERDs can make it much easier to grasp the structure of a database without having to examine each table individually. In this section you will learn to read these diagrams, understand the relationships between tables, and apply this knowledge to create and query tables.
# Part 1 Lessons and Practice Questions (8 pts)
Click into each of the lessons below for the practice questions
# Entity Relationship Diagram Structure
# Representing Relationships
# Data Types and Nullability
# Querying from Entity Relationship Diagrams
# Create Tables and Manage Data
# CREATE, ALTER, DROP
Full List of Data Types - SQL Data Types for MySQL, SQL Server, and MS Access
# INSERT, UPDATE, DELETE
# Constraints
# Part 2 Practice Questions (6 pts)
Create a new database called Reservations
for part 2. Make sure to USE
it when writing queries.
Write the CREATE and INSERT statements for the tables below. Use your best judgement to assign appropriate data types and constraints to your columns. After each CREATE statement, write a brief comment to give your reasoning for using (or not using) constraints on each of the columns.
# Guests
ID | FirstName | LastName | Phone |
---|---|---|---|
1 | Nathaniel | Mandrake | (111) 222 3333 |
2 | David | Martinez | (333) 444 5555 |
3 | Valentine | Wiggin | (666) 777 8888 |
# Reservations
ID | GuestID | RestaurantID | ReservationDateTime |
---|---|---|---|
1 | 3 | 2 | 2024-01-02 19:00:00 |
2 | 1 | 1 | 2024-01-03 9:30:00 |
3 | 2 | 1 | 2024-01-03 10:00:00 |
4 | 3 | 2 | 2024-01-04 17:30:00 |
# Restaurants
ID | Name |
---|---|
1 | Bob’s Gourmet Macaroni |
2 | Cheese Louise Dinner |
# Part 3 Practice Questions (6 pts)
Create a new database called Cars
for part 3. Make sure to USE
it when writing queries. Create 2nd SQL file for your part 3 scripts.
|
|
Without using CREATE or INSERT, write SQL commands to handle the following scenarios for this car dealership database.
- The dealership has decided to start tracking the color of each car.
- There was a mistake when processing a recent order. The Honda Civic was actually sold to John Smith.
- Mei Chen has decided to return her Tesla Model 3. The dealership has agreed to take it back.
- Aisha Patel has changed her email address. Her new email is aishap@gmail.com.
- Due to a special promotion, the dealership has decided to reduce the price of the Ford Mustang by $2000.
- Kwame has decided to close their account. Data privacy laws require the company to permanently remove their information.
# How to Submit
You will have 3 deliverables for this assignment:
- For part 1, paste in your answers to the text area or upload a PDF/Word document or a .txt or .sql file.
- For part 2, submit a SQL script with your CREATE and INSERT statements.
- For part 3, submit a SQL script with the table CREATEs and INSERTs provided as well as your queries for questions 1-6.
Upload / submit these files for the “M6 Practice - Entity Relationship Diagrams and Table Creation” assignment.