0% found this document useful (0 votes)
24 views12 pages

Data Modeling with SQLite and ER Diagrams

The document provides guidelines for an assignment on data modeling. It discusses conceptual and logical data modeling using ER diagrams for a case study application. It also describes using SQLite as the database system and provides examples of physical data models for various tables with attributes and constraints.

Uploaded by

Hoài Linh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views12 pages

Data Modeling with SQLite and ER Diagrams

The document provides guidelines for an assignment on data modeling. It discusses conceptual and logical data modeling using ER diagrams for a case study application. It also describes using SQLite as the database system and provides examples of physical data models for various tables with attributes and constraints.

Uploaded by

Hoài Linh
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

SOFTWARE DESIGN AND CONSTRUCTION


Assignment 04 – Data Modeling
Lecturer: NGUYEN Thi Thu Trang, trangntt@[Link]

1. SUBMISSION GUIDELINE
When you want to submit your individual work of in-class tasks for the Case Study,
you have to push your work to your individual GitHub repository, complied with
the naming convention “[Link]” (e.g.
[Link] or [Link].20231-
[Link]).

2. IN-CLASS ASSIGNMENT
In this section, we will get familiar with the software detailed design process and
try ourselves with data modeling for the Case Study.
You are asked to work individually for this section, and then put all your file(s) and
directories to a directory, namely “DetailedDesign/DataModeling”. After that, push
your commit to your individual repository before the announced deadline.
You may need free tools such as MySQL Workbench, moqups with template1, and
[Link], or paid apps like Astah Pro, Navicat, and DataGrip in this lab for the
purpose of data modeling.

2.1. CONCEPTUAL DATA MODEL


Conceptual data model is a high-level data model that abstracts the natural
expressions without any constraints imposed by database management system
(DBMS) like PostgreSQL, SQLite, Microsoft Access, or MongoDB. A conceptual data
model can be expressed by Entity-Relationship (ER) diagram,
To illustrate, we will create an ER diagram for AIMS.

1 [Link]
HANDS-ON LAB GUIDELINES
© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
2

2.2. DATABASE DESIGN


In this part, we need specify what is the decision of the Database Management
System (DBMS) and describe the DBMS.
For example, we would use SQLite 3.7.2 as our DBMS of the Case Study. We choose
SQLite because:

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
3

- SQLite is an open-source relational database management system.


- It is not only a small, fast, popular, self-contained, high-reliability, full-
featured, SQL database engine but also stable, cross-platform, and
backwards compatible with long-term support 2.
- It has bindings to Java. See [Link]
On the other hand, SQLite cannot work as a server-side database like MySQL or
PostgreSQL, which any ecommerce system would need, since it stores user data in
the local device.
In this course, we, however, use SQLite since the sample project for the Case Study
only runs locally, and it is still able to give sufficient illustration to the learners.
Note that SQLite is used for students to practice with DB, but not suitable for such
real-life e-commerce system.

2.2.1. Logical Data Model


From the conceptual data model (i.e., ER diagram) in the previous section, we can
achieve the logical data model with respect to the chosen DBMS (i.e., SQLite).
Here is a logical data model regarding our ER diagram.

2 [Link]
HANDS-ON LAB GUIDELINES
© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
4

2.2.2. Physical Data Model


In this part, we need to give a detail design of each element in the DB diagram. For
instance, in a Relational DBMS, we give a detail design for each Table and their
constraints, illustrated in below table (PK: Primary Key, FK: Foreign Key).
- Media

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID, auto increment

2. category VARCHAR(45) Yes Media type, e.g., CD, DVD

3. price Integer Yes Current price

4. quantity Integer Yes Number of products

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
5

# PK FK Column Data type Mandatory Description


Name

5. title VARCHAR(45) Yes Product name

6. value Integer Yes Value of the product

7. imageUrl VARCHAR(45) Yes Product image path

- CD

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID, same as ID of Media of


which type is CD

2. artist VARCHAR(45) Yes Artist's name

3. recordLabel VARCHAR(45) Yes Record label

4. musicType VARCHAR(45) Yes Music genres

5. releasedDate DATE No Release date

- Book

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID, same as ID of Media of


which type is Book

2. author VARCHAR(45) Yes Author

3. coverType VARCHAR(45) Yes Cover type

4. Publisher VARCHAR(45) Yes Publishing house

5. publishDate DATETIME Yes Date of publishing

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
6

# PK FK Column Data type Mandatory Description


Name

6. numOfPages Integer Yes Page number

7. language VARCHAR(45) Yes Language

8. bookCategory VARCHAR(45) Yes Book category

- DVD

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID, same as ID of Media of


which type is DVD

2. discType VARCHAR(45) Yes Disc type

3. director VARCHAR(45) Yes Director

4. runtime Integer Yes Duration

5. studio VARCHAR(45) Yes Manufacturer

6. subtitle VARCHAR(45) Yes Subtitles

7. releasedDate DATETIME Yes Release date

8. filmType VARCHAR(45) Yes Genres

- Card

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID, auto increment

2. cardCode VARCHAR(45) Yes Card code

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
7

# PK FK Column Data type Mandatory Description


Name

3. owner VARCHAR(45) Yes Cardholders

4. cvvCode VARCHAR(3) Yes CVV code

5. dateExpired VARCHAR(4) Yes Expiration date

- DeliveryInfo

# PK FK Column Data type Mandatory Description


Name

1. X id Integer Yes ID, auto increment

2. name VARCHAR(45) Yes Receiver name

3. province VARCHAR(45) Yes Provinces

4. instructions VARCHAR(200) No Delivery instructions

5. address VARCHAR(100) Yes Delivery address

- Order

# PK FK Column Data type Mandatory Description


Name

1. X id Integer Yes ID

2. shippingFees VARCHAR(45) Yes Shipping fee

3. X deliveryInfoId Integer Yes Delivery Info ID

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
8

- OrderMedia

# PK FK Column Data type Mandatory Description


Name

1. X mediaID Integer Yes Media ID

2. X orderID Integer Yes Order ID

3. price Integer Yes Selling price

4. quantity Integer Yes Number

- Invoice

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID

2. totalAmount Integer Yes Total

3. x orderId Integer Yes Order ID

- PaymentTransaction

# PK FK Column Data type Mandatory Description


Name

1. x id Integer Yes ID

2. createAt DATETIME Yes Date of creation

3. content VARCHAR(45) Yes Transaction contents

4. method VARCHAR(45) Yes Payment methods

5. x cardId Integer Yes ID of used card

6. x invoiceId Integer Yes Invoice ID

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
9

Finally, we need a database script. With specialized database development tools


and plugins, we can generate a database script directly from logical data model.
BEGIN;
CREATE TABLE "aims"."Media"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"category" VARCHAR(45) NOT NULL,
"price" INTEGER NOT NULL,
"quantity" INTEGER NOT NULL,
"title" VARCHAR(45) NOT NULL,
"value" INTEGER NOT NULL,
"imageUrl" VARCHAR(45) NOT NULL
);
CREATE TABLE "aims"."CD"(
"id" INTEGER PRIMARY KEY NOT NULL,
"artist" VARCHAR(45) NOT NULL,
"recordLabel" VARCHAR(45) NOT NULL,
"musicType" VARCHAR(45) NOT NULL,
"releasedDate" DATE,
CONSTRAINT "fk_CD_Media1"
FOREIGN KEY("id")
REFERENCES "Media"("id")
);
CREATE TABLE "aims"."Book"(
"id" INTEGER PRIMARY KEY NOT NULL,
"author" VARCHAR(45) NOT NULL,
"coverType" VARCHAR(45) NOT NULL,
"publisher" VARCHAR(45) NOT NULL,
"publishDate" DATETIME NOT NULL,
"numOfPages" INTEGER NOT NULL,
"language" VARCHAR(45) NOT NULL,
"bookCategory" VARCHAR(45) NOT NULL,
HANDS-ON LAB GUIDELINES
© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
10

CONSTRAINT "fk_Book_Media1"
FOREIGN KEY("id")
REFERENCES "Media"("id")
);
CREATE TABLE "aims"."DeleveryInfo"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"name" VARCHAR(45),
"province" VARCHAR(45),
"instructions" VARCHAR(200),
"address" VARCHAR(100)
);
CREATE TABLE "aims"."Card"(
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
"cardCode" VARCHAR(15) NOT NULL,
"owner" VARCHAR(45) NOT NULL,
"cvvCode" VARCHAR(3) NOT NULL,
"dateExpired" VARCHAR(4) NOT NULL
);
CREATE TABLE "aims"."DVD"(
"id" INTEGER PRIMARY KEY NOT NULL,
"discType" VARCHAR(45) NOT NULL,
"director" VARCHAR(45) NOT NULL,
"runtime" INTEGER NOT NULL,
"studio" VARCHAR(45) NOT NULL,
"subtitle" VARCHAR(45) NOT NULL,
"releasedDate" DATETIME,
CONSTRAINT "fk_DVD_Media1"
FOREIGN KEY("id")
REFERENCES "Media"("id")
);
CREATE TABLE "aims"."Order"(
HANDS-ON LAB GUIDELINES
© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
11

"id" INTEGER NOT NULL,


"shippingFees" VARCHAR(45),
"deleveryInfoId" INTEGER NOT NULL,
PRIMARY KEY("id","deleveryInfoId"),
CONSTRAINT "fk_Order_DeleveryInfo1"
FOREIGN KEY("deleveryInfoId")
REFERENCES "DeleveryInfo"("id")
);
CREATE INDEX "aims"."Order.fk_Order_DeleveryInfo1_idx" ON "Order"
("deleveryInfoId");
CREATE TABLE "aims"."OrderMedia"(
"orderID" INTEGER NOT NULL,
"price" INTEGER NOT NULL,
"quantity" INTEGER NOT NULL,
"mediaId" INTEGER NOT NULL,
PRIMARY KEY("orderID","mediaId"),
CONSTRAINT "fk_ordermedia_order"
FOREIGN KEY("orderID")
REFERENCES "Order"("id"),
CONSTRAINT "fk_OrderMedia_Media1"
FOREIGN KEY("mediaId")
REFERENCES "Media"("id")
);
CREATE INDEX "aims"."OrderMedia.fk_ordermedia_order_idx" ON "OrderMedia"
("orderID");
CREATE INDEX "aims"."OrderMedia.fk_OrderMedia_Media1_idx" ON "OrderMedia"
("mediaId");
CREATE TABLE "aims"."Invoice"(
"id" INTEGER PRIMARY KEY NOT NULL,
"totalAmount" INTEGER NOT NULL,
"orderId" INTEGER NOT NULL,

HANDS-ON LAB GUIDELINES


© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E
12

CONSTRAINT "fk_Invoice_Order1"
FOREIGN KEY("orderId")
REFERENCES "Order"("id")
);
CREATE INDEX "aims"."Invoice.fk_Invoice_Order1_idx" ON "Invoice"
("orderId");
CREATE TABLE "aims"."PaymentTransaction"(
"id" INTEGER NOT NULL,
"createAt" DATETIME NOT NULL,
"content" VARCHAR(45) NOT NULL,
"method" VARCHAR(45),
"cardId" INTEGER NOT NULL,
"invoiceId" INTEGER NOT NULL,
PRIMARY KEY("id","cardId","invoiceId"),
CONSTRAINT "fk_PaymentTransaction_Card1"
FOREIGN KEY("cardId")
REFERENCES "Card"("id"),
CONSTRAINT "fk_PaymentTransaction_Invoice1"
FOREIGN KEY("invoiceId")
REFERENCES "Invoice"("id")
);
CREATE INDEX "aims"."PaymentTransaction.fk_PaymentTransaction_Card1_idx" ON
"PaymentTransaction" ("cardId");
CREATE INDEX "aims"."PaymentTransaction.fk_PaymentTransaction_Invoice1_idx"
ON "PaymentTransaction" ("invoiceId");
COMMIT;

2.3. DATA MODELING FOR UC “PLACE RUSH ORDER”


You are asked to update the data models with use case “Place Rush Order.”
When you finish all the tasks, please export your work into a PDF file, and push
everything to your individual repository before the announced deadline.
HANDS-ON LAB GUIDELINES
© SOICT – HUST
ITSS SOFTWARE DEVELOPMENT – IT4945E

Common questions

Powered by AI

Updating data models for new use cases, like 'Place Rush Order', involves analyzing the requirements of the use case and determining necessary changes to the existing data structures. Typically, this could involve adding new attributes to tables or creating new tables to capture additional data, such as rush order fees or priority flags. It may also require modifying constraints and relationships to accommodate the rapid processing needs specific to rush orders, ensuring that the data model aligns with business logic and enhances database functionality . Testing these updates for consistency across the data model is essential .

Auto-increment primary keys, as used in 'Card' and 'DeliveryInfo' tables, simplify the process of ensuring unique identifiers for each record, which enhances database integrity and reduces manual errors . This automation supports seamless data insertion without explicit identifier management . However, drawbacks include potential gaps in sequence due to transaction failures or deletions, which may mislead in deleting or updating processes. Moreover, dependency on sequential IDs can sometimes lead to predictability issues if IDs are exposed in URLs or APIs .

During the physical data modeling phase, challenges include optimizing storage and access speed, ensuring data integrity, and dealing with varying DBMS capabilities. These challenges can be addressed by detailed database design that includes specifying data types, primary and foreign keys, and constraints for integrity, such as the use of auto-increment for primary keys and establishing reference links with foreign keys. Tools like ER diagrams aid in visualizing complex relationships . Using proper indexing techniques also enhances query performance, addressing access speed challenges .

Specific data types and constraints in relational databases enforce data integrity and consistency by defining allowed data formats and relationships between tables. For example, in the 'Book' table, data types like VARCHAR and DATETIME standardize how text and date information is stored, while constraints such as NOT NULL on the 'author' and 'publishDate' columns ensure essential information is always present . The 'DVD' table employs similar constraints, with foreign keys ensuring that entries are linked correctly to the 'Media' table, maintaining consistency across related data .

Database scripts generated from logical data models play a crucial role in academic projects by automating the creation and setup of database schemas. These scripts enable consistency across different development environments, streamline the deployment process, and reduce human errors in schema configurations . They facilitate easy updates and migrations, which are vital as project requirements evolve over time. However, relying solely on scripts without understanding underlying designs may hamper students' grasp of database intricacies, highlighting the need for balancing automation with thorough conceptual lectures .

The 'Media' table in a relational database contains columns for ID, category, price, quantity, title, value, and imageUrl, with data types like Integer and VARCHAR . The primary key (PK) is the 'id' column, which uniquely identifies each record in the table and enables efficient retrieval, ensuring data integrity. Foreign keys (FK), not explicitly mentioned in 'Media', link tables, facilitating data normalization by referencing primary keys of related tables. The definition of primary and foreign keys establishes relational links and ensures the referential integrity of the database .

Designing the 'OrderMedia' table involves considerations such as uniquely identifying records using a composite primary key of 'orderID' and 'mediaID', linking 'Order' and 'Media' tables through foreign key constraints. This structure enforces data integrity and ensures each order-media relationship is represented correctly . However, implications for performance arise since joining tables on composite keys can be complex; thus, indexing is crucial to enhance query performance . The table's design supports data normalization by avoiding redundancy, contributing to efficient data storage and integrity management .

SQLite is chosen as the DBMS for the Case Study because it is an open-source, small, fast, popular, self-contained, high-reliability, full-featured SQL database engine that is stable, cross-platform, and backwards compatible with long-term support . However, its limitation in the context of an e-commerce system is that it cannot function as a server-side database like MySQL or PostgreSQL, and stores user data on the local device, making it unsuitable for such systems .

Using tools like MySQL Workbench and draw.io for data modeling in software design courses is effective as they provide user-friendly interfaces for visualizing and manipulating data models, such as Entity-Relationship Diagrams (ERDs). These tools support conceptual understanding and practical application by allowing students to design complex databases interactively, test relationships, and generate scripts that directly map to logical and physical data models . This practical exposure is beneficial for learning and solidifying concepts in a controlled environment. However, the choice depends on availability and specific course requirements .

The conceptual data model is a high-level data model that abstracts natural expressions and does not impose constraints by DBMS . The logical data model, derived from the conceptual data model, incorporates specifics related to the chosen DBMS, such as structure and constraints . An Entity-Relationship (ER) diagram is used in the conceptual model to visually represent entities and their relationships, which aids in the transition to a logical data model .

You might also like