Database Normalization and SQL Queries for Donut Orders, Exams of Database Programming

The process of database normalization, specifically focusing on 1nf, 2nf, and 3nf, using a donut order system as an example. It includes er diagrams, table structures, and sql queries for creating tables, inserting data, and retrieving information. The document also demonstrates how to create views and indexes to optimize database performance. It is useful for understanding database design principles and sql syntax in a practical context, providing a hands-on approach to learning database management.

Typology: Exams

2024/2025

Available from 10/23/2025

Top-Grades
Top-Grades 🇺🇸

405 documents

1 / 10

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CUSTOMERID INT (fk)
DONUT_ORDER_ID INT (pk)
ers Q
NU
OA
TE
N
S
TIV
TY
AR
TC
AH
BL
A
E
R (255)
QUANTITY INT
DONUT_ORDER_ID INT (pk) (fk)
DONUT_ID INT (pk)(fk)
1NF 2NF
Highlighted fields will form a
Composite primary key. City
State and Zip were separated
And are now atomic
DONUT ORDER ID (PK)
(FK)
QUANTITY
DONUT ID (PK)(FK)
No duplicate data, each of the above tables has a Primary Key, and a key
(foreign) that can refer to another table in the group.
3NF
No
of
Keys.
transitive dependency. New table has 2
the PKs from the other tables as Foreign
ER DIAGRAM
Each table has a primary key which can refer to another one of the
tables in this group.
ORDER TABLE
DATE DATETIME
1:M
One Customer can place many Ord
Customer table has single pk
DONUT TABLE
DONUT_ID INT (pk)
DONUT_NAME VARCHAR (100)
DONUT_DESCRIPTION VARCHAR (255)
UNIT_PRICE DECIMAL (10,2)
DONUT ORDER ID
DONUT ID
DATE
CUSTOMER ID
LAST NAME
FIRST NAME
STREET ADDRESS
CITY
STATE
ZIP CODE
HOME PHONE
MOBILE PHONE
OTHER PHONE
DESCRIPTION
QTY
UNIT PRICE
NOTES
DONUT NAME
DONUT ID (PK)
DONUT NAME
DONUT DESCRIPTION
UNIT PRICE
CUSTOMER ID (PK)
LAST NAME
FIRST NAME
STREET ADDRESS
APT
CITY
STATE
ZIP CODE
HOME PHONE
MOBILE PHONE
OTHER PHONE
DATE
CUSTOMER ID (FK)
NOTES
DONUT ORDER ID
(PK)
DONUT ORDER ID
(PK)(FK)
QUANTITY
DONUT ID (PK)(FK)
DONUT ID (PK)
DONUT NAME
DONUT
DESCRIPTION
UNIT PRICE
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Database Normalization and SQL Queries for Donut Orders and more Exams Database Programming in PDF only on Docsity!

CUSTOMERID INT (fk)

DONUT_ORDER_ID INT (pk)

ers

Q

N

U

O

A

TE

N

S

TI

V

TY

AR

T

C

A

H

BL

A

E

R (255)

QUANTITY INT

DONUT_ORDER_ID INT (pk) (fk)

DONUT_ID INT (pk)(fk)

1NF 2NF

Highlighted fields will form a

Composite primary key. City

State and Zip were separated

And are now atomic

DONUT ORDER ID (PK)

(FK)

QUANTITY

DONUT ID (PK)(FK)

No duplicate data, each of the above tables has a Primary Key, and a key

(foreign) that can refer to another table in the group.

3NF

No

of

Keys.

transitive dependency. New table has 2

the PKs from the other tables as Foreign

ER DIAGRAM

Each table has a primary key which can refer to another one of the

tables in this group.

ORDER TABLE

DATE DATETIME

1:M

One Customer can place many Ord

Customer table has single pk

DONUT TABLE

DONUT_ID INT (pk)

DONUT_NAME VARCHAR (100)

DONUT_DESCRIPTION VARCHAR (255)

UNIT_PRICE DECIMAL (10,2)

DONUT ORDER ID

DONUT ID

DATE

CUSTOMER ID

LAST NAME

FIRST NAME

STREET ADDRESS

CITY

STATE

ZIP CODE

HOME PHONE

MOBILE PHONE

OTHER PHONE

DESCRIPTION

QTY

UNIT PRICE

NOTES

DONUT NAME

DONUT ORDER

ID(PK)

DATE

CUSTOMER ID

LAST NAME

FIRST NAME

STREET ADDRESS

APT

CITY

STATE

ZIP CODE

HOME PHONE

MOBILE PHONE

OTHER PHONE

NOTES

DONUT ID (PK)

DONUT NAME

DONUT DESCRIPTION

UNIT PRICE

CUSTOMER ID (PK)

LAST NAME

FIRST NAME

STREET ADDRESS

APT

CITY

STATE

ZIP CODE

HOME PHONE

MOBILE PHONE

OTHER PHONE

DATE

CUSTOMER ID (FK)

NOTES

DONUT ORDER ID

(PK)

DONUT ORDER ID

(PK)(FK)

QUANTITY

DONUT ID (PK)(FK)

DONUT ID (PK)

DONUT NAME

DONUT

DESCRIPTION

UNIT PRICE

CUSTOMER TABLE

CUSTOMER_ID INT (pk)

LAST_NAME VARCHAR (30)

FIRST_NAME VARCHAR (30)

STREET_ADDRESS VARCHAR (100)

APT INT,

CITY VARCHAR (30)

STATE VARCHAR (30)

ZIP_CODE INT

HOME_PHONE VARCHAR (20)

MOBILE_PHONE VARCHAR (20)

OTHER_PHONE VARCHAR (20)

One order can have many

different quantities

1:M

of donut types

One donut order can hold

many different quantities

of donut types

1:M

create table customers(

customer_id INT,

orderdate date,

customer_id int,

notes varchar (255)

primary key (donut_order_id)

create table donuts(

donut_id int,

donut_name varchar(100),

donut_description varchar (255),

unit_price decimal (10,2),

primary key (donut_id)

create table qty(

quantity int,

donut_order_id int,

donut_id int,

primary key (donut_order_id, donut_id)

create view customerdata as

select

concat(first_name,’ ‘,last_name) as customername,

street_address,apt,city,state,zip_code,

home_phone,mobile_phone,other_phone

from customers

insert into orders (

donut_order_id,customer_id,orderdate,notes)

values

('1','1',’2017- 12 - 14’,’plates and napkins requested’);

insert into donuts

donut_name,donut_description,unit_price,donut_id

values

('Plain','Plain Donut','1.50',’1’)

insert into qty

(quantity,donut_order_id,donut_id)

values