Unit2 Introduction To Database Systems
Unit2 Introduction To Database Systems
by Nupur
File system vs DBMS
1)Relational Data Model: This type of model designs the data in the form of rows and columns within a table. Thus, a
relational model uses tables for representing data and in-between relationships. Tables are also called relations.
2) Entity-Relationship Data Model: An ER model is the logical representation of data as objects and relationships among
them. These objects are known as entities, and relationship is an association among these entities.
3) Object-based Data Model: An extension of the ER model with notions of functions, encapsulation, and object identity,
as well. This model supports a rich type system that includes structured and collection types.
4) Semistructured Data Model: This type of data model is different from the other three data models (explained above).
The semistructured data model allows the data specifications at places where the individual data items of the same type
may have different attributes sets. The Extensible Markup Language, also known as XML, is widely used for
representing the semistructured data.
Concept of Normalization
What is Normalization?
Normalization is the process of organizing the data in the database.
Normalization is used to minimize the redundancy from a relation or set of relations. It is also used to eliminate
undesirable characteristics like Insertion, Update, and Deletion Anomalies.
Normalization divides the larger table into smaller and links them using relationships.
The normal form is used to reduce redundancy from the database table.
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken as an entity.
a. Weak Entity
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any key attribute of its
own. The weak entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id age contact number name etc can be attributes of a student
, , , , . .
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a primary key. The key attribute
is represented by an ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The composite attribute is
represented by an ellipse, and those ellipses are connected with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is
used to represent multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed
ellipse.
For example, A person's age changes over time and can be derived from another attribute like Date of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to represent the
relationship.
When only one instance of an entity is associated with the relationship, then it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to one female.
b. One-to-many relationship
When only one instance of the entity on the left, and more than one instance of an entity on the right associates with the
relationship then this is known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific scientist.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the right associates with the
relationship then it is known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on the right associates
with the relationship then it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.
Introduction to Relational Model
Relational model makes the query much easier than in hierarchical or network database systems.
A relational database is defined as a group of independent tables which are linked to each other using some
common fields of each related table.
This model can be represented as a table with columns and rows.
Each row is known as a tuple.
Each column of the table has a name or attribute.
Some popular relational databases are used nowadays like Oracle, Sybase, DB2, MySQL Server etc.
Integrity Constraints
Integrity constraints are a set of rules. It is used to maintain the quality of information.
Integrity constraints ensure that the data insertion, updating, and other processes have to be performed in such a
Thus, integrity constraint is used to guard against accidental damage to the database.
GeeksforGeeks
DBMS Integrity Constraints - GeeksforGeeks
A Computer Science portal for geeks. It contains well written, well thought and
well explained computer science and programming articles, quizzes and…
Querying relational Data using SQL
A relational database query is a question about the data, and the answer consists of a new relation containing the result.
For example, we might want to find all students AGE less than 18 or all students enrolled in particular course.
The SELECT statement is used to fetch the data from a database table which returns this data in the form of a result
table. These result tables are called result-sets.
Syntax in Mysql
SELECT column1, column2, ...
FROM table_name;
If you want to select all the fields available in the table, use the following syntax:
Syntax in Mysql
SELECT * FROM table_name;
The symbol ´*´ means that we retain all fields of selected tuples in the result.
2. ALTER:
It is used to modify the structure of an existing database object.
3. DROP:It is used to delete an entire object or part of an object from the database.
4. TRUNCATE: Used to delete all records from a table but does not delete the table structure.
Count():
Count(*): Returns the total number of records .i.e 6.
Count(salary): Return the number of Non-Null values over the column salary. i.e 5.
Count(Distinct Salary): Return the number of distinct Non-Null values over the column salary .i.e 5.
Sum():
sum(salary): Sum all Non-Null values of Column salary i.e., 3120.
sum(Distinct salary): Sum of all distinct Non-Null values i.e., 3120..
Avg():
Avg(salary) = Sum(salary) / count(salary) = 3120 / 5 = 624
Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 3120 / 5 = 624
Min():
Min(salary): Minimum value in the salary column except NULL i.e., 403.
Max():
Max(salary): Maximum value in the salary i.e., 802.
Demo SQL Database
In this tutorial on aggregate functions, we will use the following table for examples:
Id Name Salary
1 A 802
2 B 403
3 C 604
4 D 705
5 E 606
6 F NULL
You can also create this table on your system, by writing the following queries:
CREATE TABLE Employee ( Id INT PRIMARY KEY, Name CHAR(1), -- Adjust data type and length if names can be longer
than a single character Salary DECIMAL(10,2) -- Adjust precision and scale if needed for salaries );
INSERT INTO Employee (Id, Name, Salary) VALUES (1, 'A', 802), (2, 'B', 403), (3, 'C', 604), (4, 'D', 705), (5, 'E', 606), (6,
'F', NULL);
Output
TotalEmployees
6
TotalSalary
3120
AverageSalary
624
HighestSalary
802
LowestSalary
403