Introduction To Databases
Introduction To Databases
Introduction To Databases
Databases
Database Systems
What is database and write its types
A database is an organized collection of data.
Types:
There are two common types of databases
Non-Relational
Relational
Other Types of database
Centralized database
Distributed database
No SQL Database
Cloud database
Network database
Object Oriented database
Hierarchical database
Non-Relational Database
In a non-relational database, data is stored in key-value pairs.
For example:
Here, customers' data are stored in key-value pairs.
Commonly used non-relational database management systems (Non-RDBMS) are
MongoDB, Amazon DynamoDB, Redis, etc.
Relational Database
In a relational database, data is stored in tabular format.
For example
Here, customers is a table inside the database.
The first row is the attributes of the table. Each row after that contains the data of a customer.
In a relational database, two or more tables may be related to each other. Hence the
term Relational. For example,
Here, orders and customers are related through customer_id.
High-level conceptual data models provide concepts for presenting data in ways
that are close to the way people perceive data. A typical example is the entity
relationship model, which uses main concepts like entities, attributes and
relationships. An entity represents a real-world object such as an employee or a
project. The entity has attributes that represent properties such as an
employee’s name, address and birthdate. A relationship represents an association
among entities; for example, an employee works on many projects.
A relationship exists between the employee and each project.
Database Design
The third step is database design. During this step, we might have two sub-steps:
database logical design, which defines a database in a data model of a
specific DBMS.
database physical design, which defines the internal database storage
structure, file organization or indexing techniques.
These two sub-steps are database implementation and operations/user interfaces
building steps.
In the database design phases, data are represented using a certain data model.
The data model is a collection of concepts or notations for describing data, data
relationships, data semantics and data constraints. Most data models also include
a set of basic operations for manipulating data in the database.
Entity
An entity is referred to as an object or thing that exists in the real world. For
example, customer, car, pen, etc.
An entity has some attributes which depict the entity's characteristics. For
example, an entity "Student" has attributes such as "Student_roll_no",
"Student_name", "Student_subject", and "Student_marks".
Kinds of Entity
Tangible Entity
Intagible Entity
Tangible Entity
Simple attributes are those that cannot be further divided into sub-attributes.
For example
A roll number of a student or the employee identification number.
Composite Attributes
Composite attributes are made up of two or more simple attributes.
For example
A person's address may be a composite attribute that is made up of the person's
street address, city, state, and zip code.
Single Valued Attributes
Single-valued attributes can only have one value, and these values remain
constant.
For example
A person's Social Security Number is a single-valued attribute.
Multivalued Attributes
Derived attributes are based on other attributes and are not stored directly in
the database.
For example: Consider a database of employees. Each employee has a date of
birth, and we might want to calculate their age. However, age is a derived
attribute because it can be determined from the date of birth.
Complex Attributes
DBMS's key attributes are used to uniquely identify each row in a table. Usually,
there is more than one key attribute in a table (primary key and foreign key).
For example: In a table of employees, the employee ID would be the primary key,
while the manager ID would be the foreign key.
Stored Attributes
In a DBMS, stored attributes are the data that remain constant and fixed for an entity
instance. These values help in deriving the derived attributes.
For example
Consider a customer entity in a bank. The customer's name, age, and address would be
stored attributes. The customer's account balance (a derived attribute) could be calculated
based on the transactions (another stored attribute) associated with the customer.
Keys
Keys are used to uniquely identify any record or row of data from the table. It is
also used to establish and identify relationships between tables.
Following are the types of Keys:
Primary Key: It is the first key used to identify one and only one instance of
an entity uniquely.
Super Key: Super key is an attribute set that can uniquely identify a tuple. A
super key is a superset of a candidate key.
Candidate Key: A candidate key is an attribute or set of attributes that can
uniquely identify a tuple.
Alternate Key: The total number of the alternate keys is the total number of
candidate keys minus the primary key.
Foreign Key: Foreign keys are the column of the table used to point to the
primary key of another table.
Composite Key: Whenever a primary key consists of more than one attribute,
it is known as a composite key. This key is also known as Concatenated Key.
Types of Relationship
A one-to-one relationship is a link between two tables where each record in one
table only appears once in the other table.
For example
A school database might have a one-to-one relationship between students and
their student IDs, where each student has only one ID and each ID is assigned to
only one person.
One to many or many to one relationship
When one row in table “A” is linked to many rows in table “B” then it is called as
one to many relationship.
Many to many relationships
A many-to-many relationship in a database occurs when one or more items in one
table can have a relationship to one or more items in another table.
For example, a customer can have multiple orders placed by other customers,
and one order can contain one or more instances of multiple products.