Assignment DB
Assignment DB
ASSIGNMENT NUMBER: 1
2
Internal verification:
3
Table of Contents
I. Introduction................................................................................................................................6
II. Theory........................................................................................................................................6
1. Database.................................................................................................................................6
1.1 What is Database ?..........................................................................................................6
1.2 Purpose of the database:.................................................................................................6
1.3 The importance of the database:....................................................................................6
1.4 Several kind of the database...........................................................................................6
2. Relational database................................................................................................................6
2.1. What is relational database ?........................................................................................6
2.2. Components of a relational database............................................................................7
3. Entity Relationship Diagram (ERD)....................................................................................8
3.1 What is an entity relationship diagram (ERD).............................................................8
3.2. Uses of entity relationship diagrams.............................................................................8
3.3. The components of an ER diagram...............................................................................9
4. Relational Schema...............................................................................................................14
4.1 What is Relational Schema ?........................................................................................14
4.2 The purpose of Relational Schema :............................................................................14
4.3 How to convert ERD to Relational Scheme ?..............................................................14
5. Relational data management base system-RDBMS.........................................................14
5.1 What is RDBMS ?..........................................................................................................14
5.2 Role of RDBMS..............................................................................................................14
5.3 Some RDBMS................................................................................................................15
6. Database Normalization......................................................................................................15
6.1 What is database normalization ?................................................................................15
6.2 Database normalization form.......................................................................................16
7. Structured Query Language-SQL.....................................................................................18
7.1 What is SQL?.................................................................................................................18
7.2 Commonly used SQL statements.................................................................................18
8. System testing.......................................................................................................................18
8.1 What is System testing ?...............................................................................................18
8.2 Purpose of testing...........................................................................................................18
III. Practise...................................................................................................................................18
4
1. Requirements analysis.........................................................................................................18
2. Entity list..............................................................................................................................18
3. Entity's Attributes...............................................................................................................19
4. Relationship between entities.............................................................................................19
5. ERD.......................................................................................................................................20
6. Relational schema................................................................................................................20
7. Constraints in DB................................................................................................................20
8. Detailed settings...................................................................................................................21
9. DB Diagram..........................................................................................................................22
10. Query statements used in DB...........................................................................................22
10.1. On the database..........................................................................................................22
10.2. On the table.................................................................................................................22
10.4. Query...........................................................................................................................22
11. Database normalization....................................................................................................23
12. System security, database maintenance...........................................................................23
IV. Testing....................................................................................................................................23
1. Test log..................................................................................................................................23
2. Test case................................................................................................................................24
V. Technical and user documentation.......................................................................................24
1. Used RDBMS installation guide.........................................................................................24
2. RDBMS User Manual.........................................................................................................27
3. Describe how the database system works..........................................................................30
VI. Conclusion..............................................................................................................................30
1. Evaluate the effectiveness of the design.............................................................................30
2. Evaluate database to improve demand..............................................................................30
VII. References.............................................................................................................................31
5
I. Introduction
- Besides .NET programming knowledge, Java, PHP, Node.JS, Golang,.... Knowledge of
database is one of the big plus points in interview as well as working process at companies and
enterprises. Because the database is considered the heart of any software application from Web
to Mobile applications, or Data Science, Machine Learning & AI. Therefore, my goal is to learn
and improve the skills and background knowledge to be able to design databases for
applications, as well as equip the most basic foundation to start developing myself.
II. Theory
1. Database
- Document store
- Key-value database
- Wide-column model
6
2. Relational database
In a relational database, a table is the same as a record, which is the fundamental data
component. It is comprised of a set of fields that are the same in every table or record, such as
the name, address and product of the customer. Relational databases also dictate how the tables
work. For example, relational databases control how the data is presented on-screen and
organized for output dictated by query and data definition language and even how much
information can be stored in a given field.
- Rows
Relational database tables look much like an Excel spreadsheet when diagrammed for visual
reference. The rows in each database table represent sequential values where the value in row
1A, for example, relates to the values in all the other fields in row 1. The type of value in row
1A, i.e. the name John Smith, is the same type of value as in all other rows in column A. Each
row represents the sum of data for an entire record or a subcategory of a record, such as customer
contact information that would include John Smith's address, telephone number and email
address.
- Columns
Columns in a relational database table are control features; each column represents a field of data
that occurs consistently in each record or table throughout the database. For example, in the
model CRM database visual representation, the columns would have headers such as "name,"
"address," "telephone" and "email." These column names are the names of the data fields that
occur in each record.
- Primary Keys
Primary keys are identification tags for each row of data. The primary key is different for every
record in the relational database; it must be unique and it must exist (in other words, it can not be
"null"). In the CRM database, this primary key might be a number assigned to the customer or be
a unique identifier such as her Social Security number. Primary keys are used for queries within
the relational database but not for queries to external databases.
- Foreign Keys
Foreign keys allow data searches and manipulation between the primary database table and other
related databases. In the CRM model, there might be a database of product types, listing
manufacturers of different widgets. Each widget type would be assigned a foreign key allowing
7
the CRM user to make a search to determine if a certain customer is one its manufacturers. For
example, a widget category called "X" might be assigned the foreign key of "1," and have many
subcategories labeled alphabetically. The search for foreign key 1 shows how many items are in
category X, and when an item is viewed, the record shows its category designation.
ER diagrams are related to data structure diagrams (DSDs), which focus on the relationships of
elements within entities instead of relationships between entities themselves. ER diagrams also
are often used in conjunction with data flow diagrams (DFDs), which map out the flow of
information for processes or systems.
8
3.2. Uses of entity relationship diagrams
- Database design: ER diagrams are used to model and design relational databases, in terms of
logic and business rules (in a logical data model) and in terms of the specific technology to be
implemented (in a physical data model.) In software engineering, an ER diagram is often an
initial step in determining requirements for an information systems project. It’s also later used to
model a particular database or databases. A relational database has an equivalent relational table
and can potentially be expressed that way as needed.
- Database troubleshooting: ER diagrams are used to analyze existing databases to find and
resolve problems in logic or deployment. Drawing the diagram should reveal where it’s going
wrong.
- Business information systems: The diagrams are used to design or analyze relational databases
used in business processes. Any business process that uses fielded data involving entities, actions
and interplay can potentially benefit from a relational database. It can streamline processes,
uncover information more easily and improve results.
- Education: Databases are today’s method of storing relational information for educational
purposes and later retrieval, so ER Diagrams can be valuable in planning those data structures.
- Research: Since so much research focuses on structured data, ER diagrams can play a key role
in setting up useful databases to analyze the data.
A definable thing such as a person, object, concept or event that can have data stored about it.
Think of entities as nouns. Examples: a customer, student, car or product. Typically shown as a
rectangle.
- Entity type: A group of definable things, such as students or athletes, whereas the entity would
be the specific student or athlete. Other examples: customers, cars or products.
- Entity set: Same as an entity type, but defined at a particular point in time, such as students
enrolled in a class on the first day. Other examples: Customers who purchased last month, cars
currently registered in Florida. A related term is instance, in which the specific person or car
would be an instance of the entity set.
- Entity categories: Entities are categorized as strong, weak or associative. A strong entity can be
defined solely by its own attributes, while a weak entity cannot. An associative entity associates
entities (or elements) within an entity set.
9
- Entity keys: Refers to an attribute that uniquely defines an entity in an entity set. Entity keys
can be super, candidate or primary.
- Super key: A set of attributes (one or more) that together define an entity in an entity set.
- Candidate key: A minimal super key, meaning it has the least possible number of attributes to
still be a super key. An entity set may have more than one candidate key.
- Primary key: A candidate key chosen by the database designer to uniquely identify the entity
set.
b. Relationship
How entities act upon each other or are associated with each other. Think of relationships as
verbs. For example, the named student might register for a course. The two entities would be the
student and the course, and the relationship depicted is the act of enrolling, connecting the two
entities in that way. Relationships are typically shown as diamonds or labels directly on the
connecting lines.
Recursive relationship: The same entity participates more than once in the relationship.
c.Attribute
10
Descriptive attribute: A property or characteristic of a relationship (versus of an entity.)
Attribute categories: Attributes are categorized as simple, composite, derived, as well as single-
value or multi-value.
Simple: Means the attribute value is atomic and can’t be further divided, such as a phone
number.
Derived: Attributed is calculated or otherwise derived from another attribute, such as age from a
birthdate.
Multi-value: More than one attribute value is denoted, such as multiple phone numbers for a
person.
Single-value: Just one attribute value. The types can be combined, such as: simple single-value
attributes or composite multi-value attributes.
d. Cardinality
Defines the numerical attributes of the relationship between two entities or entity sets.
The three main cardinal relationships are one-to-one, one-to-many, and many-many. A one-to-
one example would be one student associated with one mailing address. A one-to-many example
(or many-to-one, depending on the relationship direction): One student registers for multiple
courses, but all those courses have a single line back to that one student. Many-to-many
11
example: Students as a group are associated with multiple faculty members, and faculty
members in turn are associated with multiple students.
- ERD symbols
12
- Some ERD drawing tools:
+ Microsoft Visio
+ QuickDBD
+ Slickplan
+ drawSQL
+ Lucidchart
+ DbSchema
+ SchemaSpy
+ DeZign
+ Visual Paradigm
+ Moqups
+ Dbdiagram.io
+ SqlDBM
+ Dbdesigner.net
+ Toad World
13
+ Dataedo
+ Vertabelo
+ Dmodelaid
+ Draw.io
=> I’ll use Draw.io to draw ERD Phone Manager Software because:
- This entity relationship diagram tool works on all browsers, including Chrome, Firefox, and
Internet Explorer.
- You can build database diagrams in a variety of formats, including UML (Unified Modeling
Language), ERD, and others.
4. Relational Schema
14
5. Relational data management base system-RDBMS
RDBMSs store data as "relational": tables with lines and columns where all data information is
stored as a value of a specific cell. Data in an RDBMS is managed through the well-known SQL
protocol – structured query language.
- Provides a way to update and exploit data: The DBMS provides users with a data manipulation
language to express database requests, updates, and operations. Data manipulation includes:
Update (import, edit, delete data), Mining (search, dump data).
- Provide tools to control and control access to the database to ensure the fulfillment of some
basic requirements of the database system. Including:
- MySQL
- MS SQL Server
- PostgreSQL
15
- Maintain separate production, development and testing environments.
6. Database Normalization
16
b. 2NF (Second Normal Form) Rules
- Rule 1- Be in 1NF.
- Rule 2- Single Column Primary Key that does not functionally dependant on any subset
of candidate key relation.
17
6th Normal Form is not standardized, yet however, it is being discussed by database
experts for some time. Hopefully, we would have a clear & standardized definition for
6th Normal Form in the near future…
- SELECT
- WHERE
- INSERT INTO
- UPDATE
- DELETE
- JOINS
8. System testing
III. Practise
1. Requirements analysis
- Database design for HirePhone Store software to help manage and sell phone products.
18
- There must be ways for customers to buy phones conveniently.
2. Entity list
- admin, warehouse, customer, phone, order, product catalog, shipper, payment methods
3. Entity's Attributes
- admin: ID, Name, username, password
- phone: ID, IMEI, name, releasedate, capacity, size, manufacturer, color, price
19
5. ERD
6. Relational schema
7. Constraints in DB
NOT NULL make sure the column data doesn't have NULL values
UNIQUE this column value is unique (different rows lead to different values)
DEFAULT the default value of the column if the insertion does not include a value
20
PRIMARY KEY is a combination of and , this value is used to identify the different rows of the
table (Abbreviated PK, Pk)NOT NULL UNIQUE
FOREIGN KEY is the only value referenced from another table (Abbreviations FK, Fk)
8. Detailed settings
CREATE TABLE admins(
id INT NOT NULL IDENTITY PRIMARY KEY,
admins adname VARCHAR(255),
username VARCHAR(255) NOT NULL,
pw VARCHAR(20) NOT NULL,);
CREATE TABLE customer(
id INT IDENTITY (1, 1) PRIMARY KEY,
customer cname VARCHAR(255) NOT NULL,
phonenumber VARCHAR(10) NOT NULL,);
CREATE TABLE orders(
id INT IDENTITY (1, 1) PRIMARY KEY,
odate VARCHAR(255) NOT NULL,
phonenumber VARCHAR(25) NOT NULL,
status VARCHAR(40) NOT NULL,
address VARCHAR(255) NOT NULL,);
ALTER TABLE orders
orders ADD id_ad INT FOREIGN KEY (id_ad) REFERENCES
admins(id);
ADD id_pm INT FOREIGN KEY (id_pm) REFERENCES
payment(id);
ADD id_ct INT FOREIGN KEY (id_ct) REFERENCES
customer(id);
ADD id_shipper INT FOREIGN KEY (id_shipper)
REFERENCES shipper(id);
CREATE TABLE payment(
payment id INT IDENTITY (1, 1) PRIMARY KEY,
pname VARCHAR(255) NOT NULL,);
CREATE TABLE pcatalog(
id INT IDENTITY (1, 1) PRIMARY KEY,
pcatalog pcname VARCHAR(255) NOT NULL,
amount INT NOT NULL,);
CREATE TABLE phone(
id INT IDENTITY (1, 1) PRIMARY KEY,
id_wh INT FOREIGN KEY (id_wh) REFERENCES
warehouse(id),
imei VARCHAR(255) NOT NULL,
phonename VARCHAR(255) NOT NULL,
rdate VARCHAR(255) NOT NULL,
capacity VARCHAR(255) NOT NULL,
phone psize VARCHAR(255) NOT NULL,
manufacturer VARCHAR(255) NOT NULL,
color VARCHAR(255) NOT NULL,
price VARCHAR(255) NOT NULL,);
ALTER TABLE phone
ADD id_od INT FOREIGN KEY (id_od) REFERENCES
orders(id);
ADD id_pc INT FOREIGN KEY (id_pc) REFERENCES
pcatalog(id);
shipper CREATE TABLE shipper(
id INT IDENTITY (1, 1) PRIMARY KEY,
sname VARCHAR(255) NOT NULL,
21
phonenumber VARCHAR(10) NOT NULL,);
CREATE TABLE warehouse(
id INT NOT NULL IDENTITY PRIMARY KEY,
warehouse id_ad INT FOREIGN KEY (id_ad) REFERENCES
admins(id),
totalproduct INT NOT NULL,);
9. DB Diagram
10.4. Query
SELECT * From phone
22
SELECT * FROM orders INNER JOIN phone ON orders.id = phone.id_od ;
IV. Testing
1. Test log
When i update the price with data type MONEY value '1tr9' giving error.
23
2. Test case
Once downloaded we will get a .exe file named as “SSMS-Setup-ENU.exe.” Double click on it.
24
Below window will appear. Click on ‘Install’ button to install SQL Server Management Studio
(SSMS) on your system
Installation will begin. Below screen will show Packages progress and Overall Progress.
25
Step 4: Setup is done.
Once Completed, SSMS Setup will show the below screen with “Setup Completed” message.
26
2. RDBMS User Manual
Now, we’re ready to open “Management Studio. Go To Start Menu>Programs>Microsoft SQL
Server Tools 18> Microsoft SSMS 18.
Below ‘Connect to Server’ screen will appear. Server Name defaults to the name selected while
installing MS SQL server.
27
Let’s understand each of the above fields
- Server type: This is an option to select one out of four available MS SQL services option. We
will be working on ‘Database Engine’ for creating and working with Database. Other Server type
includes Analysis, Reporting & Integration Services.
- Server name: This is Server’s name where MS SQL Server is installed and need to establish
the connection with that server. Generally, we use the server name as “Machine name\Instance.”
Here Instance is the name given to SQL Server instance while SQL server installation.
28
Below is the start screen for Data Management Studio.
1) Object Explorer
The Object Explorer provides a tree view of the database objects contained in the server. This
section shows all the Databases, Security, Server Object for quick reference. To view the
components of each object, just click the + icon located to the left of the object which will
expand it.
This dropdown allows the user to select the Database in which we will be running our queries.
3) Query Editor
29
Here we can write all our queries. MS SQL server provides interactive suggestions for tables,
columns, etc. for easy queries creations and much more.
4) Execute button
This button will finally execute the query and return the results.
VI. Conclusion
30
VII. References
https://tel4vn.edu.vn/cac-loai-co-so-du-lieu/
https://www.lucidchart.com/pages/er-diagrams
https://www.guru99.com/sql-server-management-studio.html
https://bkhost.vn/blog/sql-server-management-studio/
https://en.wikipedia.org/wiki/SQL
31