0% found this document useful (0 votes)
14 views75 pages

Unit 1

The document provides an overview of database systems, including definitions of data and databases, the role of Database Management Systems (DBMS), and the differences between data and information. It discusses the relational model, key concepts such as relations, tuples, and attributes, as well as the Entity-Relationship (ER) model for visualizing data relationships. Additionally, it outlines the advantages and disadvantages of DBMS, along with its characteristics and various roles within a database environment.

Uploaded by

dev soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views75 pages

Unit 1

The document provides an overview of database systems, including definitions of data and databases, the role of Database Management Systems (DBMS), and the differences between data and information. It discusses the relational model, key concepts such as relations, tuples, and attributes, as well as the Entity-Relationship (ER) model for visualizing data relationships. Additionally, it outlines the advantages and disadvantages of DBMS, along with its characteristics and various roles within a database environment.

Uploaded by

dev soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 75

Unit 1

Database System and Data Models ,Data base System


Applications,
z Purpose of Database Systems, View of Data
z
What is Data?

 Data is a collection of a distinct small unit of information. It can be


used in a variety of forms like text, numbers, media, bytes, etc. it
can be stored in pieces of paper or electronic memory, etc.
 Word 'Data' is invented from the word 'datum' that means 'single
piece of information.' It is plural of the word datum.
 In computing, Data is information that can be translated into a form
for efficient movement and processing. Data is interchangeable.
z
What is Database?

 A database is an organized collection of data, so that it


can be easily accessed and managed.
 You can organize data into tables, rows, columns, and
index it to make it easier to find relevant information.
 Database handlers create a database in such a way that
only one set of software program provides access of data
to all the users.
Continue..
z
 Database handlers create a database in such a way that only
one set of software program provides access of data to all the
users.
 The main purpose of the database is to operate a large amount
of information by storing, retrieving, and managing data.
 There are many dynamic websites on the World Wide Web
nowadays which are handled through databases. For example, a
model that checks the availability of rooms in a hotel. It is an
example of a dynamic website that uses a database.
 There are many databases available like MySQL, Sybase,
Oracle, MongoDB, Informix, PostgreSQL, SQL Server, etc.
 Modern databases are managed by the database management
z
Data Vs. Information
Aspect z Data Information
Raw, unprocessed facts and
Definition Processed, organized, and meaningful data
figures
Unstructured or minimally
Characteristics Structured and contextual
structured
Numbers, text, images,
Format Summarized reports, charts, analyses, etc.
audio, etc.
Collected through
Source observations, Derived from processing and analyzing data
measurements, transactions
Needs processing to be
Usage Directly useful for decision-making
useful
Interpretation Requires interpretation Already interpreted

Spreadsheet of numbers,
Sales report, temperature trend chart, customer
Examples list of dates, database
demographics
entries
z
Example of data and information

• Data Example: "100", "200", "300", "400"

• Information Example: "The quarterly sales for


the year were 100 units, 200 units, 300 units, and
400 units, showing a steady increase each
quarter."
z
Introduction of the DBMS
 A Database Management System (DBMS) is a
software system that is designed to manage and
organize data in a structured manner. It allows users
to create, modify, and query a database, as well as
manage the security and access controls for that
database.
 DBMS provides an environment to store and retrieve
the data in convenient and efficient manner.
DBMS allows users the following tasks:
z

 Data Definition: It is used for creation, modification, and removal


of definition that defines the organization of data in the database.
 Data Updation: It is used for the insertion, modification, and
deletion of the actual data in the database.
 Data Retrieval: It is used to retrieve the data from the database
which can be used by applications for various purposes.
 User Administration: It is used for registering and monitoring
users, maintain data integrity, enforcing data security, dealing with
concurrency control, monitoring performance and recovering
information corrupted by unexpected failure.
Advantages of DBMS

 Controlsz database redundancy: It can control data redundancy because it


stores all the data in one single database file and that recorded data is
placed in the database.

 Data sharing: In DBMS, the authorized users of an organization can share


the data among multiple users.

 Easily Maintenance: It can be easily maintainable due to the centralized


nature of the database system.

 Reduce time: It reduces development time and maintenance need.

 Backup: It provides backup and recovery subsystems which create


automatic backup of data from hardware and software failures and
restores the data if required.

 multiple user interface: It provides different types of user interfaces like


graphical user interfaces, application program interfaces
Disadvantages of DBMS

 Cost of zHardware and Software: It requires a high speed of


data processor and large memory size to run DBMS software.
 Size: It occupies a large space of disks and large memory to
run them efficiently.
 Complexity: Database system creates additional complexity
and requirements.
 Higher impact of failure: Failure is highly impacted the
database because in most of the organization, all the data
stored in a single database and if the database is damaged
due to electric failure or database corruption then the data
may be lost forever.
Characteristics of DBMS

z
Data Storage, Retrieval, and Update:
 Storage Management: DBMS stores data in a structured way, ensuring efficient storage and
retrieval.
 Retrieval: Provides powerful query capabilities to retrieve data quickly and efficiently.
 Update: Supports the insertion, updating, and deletion of data.
Data Security and Integrity:
 Security: Implements access control mechanisms to protect data from unauthorized access.
 Integrity: Enforces data integrity constraints to ensure data accuracy and consistency.
Backup and Recovery:
 Provides mechanisms to back up data regularly and restore it in case of data loss due to system
failures, ensuring data availability.
User Interface:
 Provides interfaces for users to interact with the database, such as SQL query interfaces,
application programming interfaces (APIs), and graphical user interfaces (GUIs).
z
Example: STUDENT Relation
z

 In the given table, NAME, ROLL_NO, PHONE_NO,


ADDRESS, and AGE are the attributes.
 The instance of schema STUDENT has 5 tuples.

 t3 = <Laxman, 33289, 8583287182, Gurugram, 20>


z
DBMS roles

 In DBMS, roles are groups of privileges


that can be assigned to users to
manage their access and permissions
efficiently.
DBMS roles
z
 Database Administrator (DBA): Manages the entire database, including backups,
security, and performance.

 Data Architect: Designs database structures, like tables and relationships.

 Database Developer: Writes and optimizes SQL queries and database scripts.

 Data Analyst/Scientist: Analyzes data, typically with extensive read access.

 Application Developer: Develops applications that interact with the database.

 End User: Uses applications to query or manipulate specific data.

 Security Administrator: Manages user access and database security.


Advantages of DBMS
 z
Data Integrity: Ensures accurate and consistent data.

 Security: Protects data from unauthorized access.

 Data Independence: Separates data from application logic.

 Efficient Management: Improves data handling performance.

 Redundancy Control: Reduces duplicate data.

 Data Sharing: Enables multiple users to access data concurrently.

 Backup and Recovery: Protects against data loss.

 Consistency: Maintains data uniformity across the system.

 Scalability: Easily handles increasing amounts of data and users.

 Standardization: Supports standardized query languages like SQL, making it


easier to interact with and manage the database.
z
The relational model in (DBMS)

 The relational model in a Database Management System


(DBMS) is a framework for managing and organizing data. It
represents data as a collection of tables, known as relations.
Each table consists of rows (also called tuples) and columns
(also called attributes). The relational model is widely used
because it provides a clear, logical structure for data storage
and allows for powerful querying through Structured Query
Language (SQL).
The relational model key concepts
1. Relation
z (Table):
o A relation is a table in the database.
o It consists of rows and columns.
o Each row represents a unique record, and each column
represents an attribute of the record.
2. Tuple (Row):
o A tuple is a single row in a relation.
o It represents a single record in the table.
o A tuple contains a set of attribute values.
3. Attribute (Column):
o An attribute is a column in a relation.
o It represents a specific property or characteristic of the relation.
z
1. Domain:
o The domain is the set of possible values for a given attribute.
o For example, the domain for an "age" attribute might be all non-negative integers.

2. Primary Key:
o A primary key is a unique identifier for a tuple in a relation.
o It ensures that no two rows have the same value(s) for the primary key attribute(s).
o A primary key can be a single attribute or a combination of attributes (composite
key).

3. Foreign Key:
o A foreign key is an attribute or a set of attributes in one relation that refers to the
primary key in another relation.
o It creates a relationship between two tables, ensuring referential integrity.
z

1. Schema:
o The schema defines the structure of the database, including the tables, attributes,
and their relationships.
o It is the blueprint of the database.

2. Instance:
o An instance is the actual data in the database at a particular moment.
o It refers to the content of the database at a given time.
ER Model in DBMS
z

 An ER Diagram (Entity-Relationship Diagram) is a visual


representation of the data and its relationships in a
database.

 It uses diagrams to visually represent the structure of data in


terms of entities, attributes, and relationships.
 Entity: A real-world object or concept (e.g., Student, Course).

 Attribute: A property or characteristic of an entity (e.g., StudentID,


Name).
 Relationship: How entities are related (e.g., Enrolls, Teaches).

 Cardinality: Specifies the number of instances in a relationship (e.g.,


z
Symbols Used in ER Model

 Rectangles: Rectangles represent Entities in the ER Model.

 Ellipses: Ellipses represent Attributes in the ER Model.

 Diamond: Diamonds represent Relationships among Entities.

 Lines: Lines represent attributes to entities and entity sets with other
relationship types.

 Double Ellipse: Double Ellipses represent Multi-Valued Attributes.

 Double Rectangle: Double Rectangle represents a Weak Entity.


z
Components of ER Diagram
z
Strong Entity
z
 A Strong Entity is a type of entity that has a key Attribute. Strong
Entity does not depend on other Entity in the Schema. It has a
primary key, that helps in identifying it uniquely, and it is
represented by a rectangle. These are called Strong Entity
Types.
Weak Entity
z
 A weak entity is a special type of entity in a database that
cannot be uniquely identified by its own attributes alone.
Instead, it depends on a "strong" or "owner" entity to ensure
its uniqueness.
 For Example, A company may store the information of
dependents (Parents, Children, Spouse) of an Employee. But
the dependents can’t exist without the employee. So
Dependent will be a Weak Entity Type and Employee will be
Identifying Entity type for Dependent, which means it is
Strong Entity Type.
z
Attributes
z

Attributes are the properties that define the entity


type. For example, Roll_No, Name, DOB, Age,
Address, and Mobile_No are the attributes that
define entity type Student. In ER diagram, the
attribute is represented by an oval.
Types of Attributes
z

Key Attribute
 The attribute which uniquely identifies each entity in the
entity set is called the key attribute. For example,
Roll_No will be unique for each student. In ER diagram,
the key attribute is represented by an oval with
underlying lines.
z

2. Composite Attribute

A composite key is the DBMS key having two or more


attributes that together can uniquely identify a tuple in a
table. Such a key is also known as Compound Key, where
each attribute creating a key is a foreign key in its own
right.
z
z
Multivalued Attribute
z

 An attribute consisting of more than one value


for a given entity. For example, Phone_No (can
be more than one for a given student). In ER
diagram, a multivalued attribute is represented
by a double oval.
Derived Attribute
z

 An attribute that can be derived from other


attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In
ER diagram, the derived attribute is represented
by a dashed oval.
z
The Complete Entity Type Student with its Attributes can be represented
as:
z
Relationship Type and Relationship Set

 A Relationship Type represents the association between


entity types. For example, ‘Enrolled in’ is a relationship
type that exists between entity type Student and Course.
In ER diagram, the relationship type is represented by a
diamond and connecting the entities with lines.
z
Degree of a Relationship Set
z
 The number of different entity sets participating in a relationship set is
called the degree of a relationship set.
 Unary Relationship: In this type of relationship, both the associating
entity types are the same. So, we can say that unary relationships exist
when both entity types are the same and we call them the degree of
relationship is 1. In other words, in a relation only one entity set is
participating then such type of relationship is known as a unary
relationship.
 Example: In a particular class, we have many students, there are
monitors too. So, here class monitors are also students. Thus, we can
say that only students are participating here. So the degree of such type
of relationship is 1.
z
z
Binary Relationship:

Involves two entity sets. This is the most common type, such as a
relationship between Customer and Order.
z
Ternary Relationship:
Involves three entity sets. For example, a
relationship involving Student, Course, and
Instructor.
z
z

 Here is the diagram representing a ternary relationship:

• The entities involved are Student, Course, and Instructor.

• The relationships are:


• A Student enrolls in a Course.
• A Course is taught by an Instructor.
• An Instructor guides the Student.
z
Cardinality

 The number of times an entity of an entity set


participates in a relationship set is known as
cardinality. Cardinality can be of different types:
One-to-One:
 When each
z entity in each entity set can take part only once in the
relationship, the cardinality is one-to-one. Let us assume that a
male can marry one female and a female can marry one male. So
the relationship will be one-to-one.
 the total number of tables that can be used in this is 2.
One-to-Many
z
 In one-to-many mapping as well where each entity can be related to
more than one entity and the total number of tables that can be
used in this is 2. Let us assume that one surgeon department can
accommodate many doctors. So the Cardinality will be 1 to M. It
means one department has many Doctors.
Many-to-One:
 When
z entities in one entity set can take part only once in the
relationship set and entities in other entity sets can take part
more than once in the relationship set, cardinality is many to
one. Let us assume that a student can take only one course but
one course can be taken by many students. So the cardinality
will be n to 1. It means that for one course there can be n
students but for one student, there will be only one course.
Many-to-Many:
 Whenz entities in all entity sets can take part more than
once in the relationship cardinality is many to many. Let
us assume that a student can take more than one
course and one course can be taken by many students.
So the relationship will be many to many.
SQL (Structured Query Language)
z

 is the database language by which we can perform certain operations on the


existing database, and we can also use this language to create a database.
SQL uses certain commands like CREATE, DROP, INSERT, etc. to carry out
the required tasks.

 SQL commands are like instructions to a table. It is used to interact with the
database with some operations. It is also used to perform specific tasks,
functions, and queries of data. SQL can perform various tasks like creating a
table, adding data to tables, dropping the table, modifying the table, set
permission for users.


These SQL commands are mainly categorized into five categories:
z

 DDL – Data Definition Language

 DQL – Data Query Language

 DML – Data Manipulation Language

 DCL – Data Control Language

 TCL – Transaction Control Language


z
DATA TYPES
z
z
Constraints

 constraints are rules that make


sure data in a table is accurate
and valid.
z
DDL (Data Definition Language)
z

 DDL or Data Definition Language actually consists


of the SQL commands that can be used to define
the database schema.
 DDL is a set of SQL commands used to create,
modify, and delete database structures but not
data. These commands are normally not used by a
general user, who should be accessing the
database via an application.
z

•CREATE: Used to create a new database object


like a table, index, or view.
•ALTER: Used to modify the structure of an
existing database object.
•DROP: Used to delete a database object.
•TRUNCATE: Used to remove all records from a
table without deleting the table itself.
SQL CREATE TABLE
z
 SQL CREATE TABLE Statement is used to create a new table in a database.

 Syntax

 To create a table in SQL, use this CREATE TABLE syntax:

CREATE table table_name

Column1 datatype (size),

column2 datatype (size),

columnN datatype(size)

);
z
Example

 CREATE TABLE Employee (

 EmployeeID INT PRIMARY KEY,

 FirstName VARCHAR(50),

 LastName VARCHAR(50),

 Department VARCHAR(50),

 Salary DECIMAL(10, 2)

 );
z
SQL DROP TABLE
DROP TABLE: Deletes the Employees table
and all of its data from the database.

Example:
DROP TABLE Employees;
z
SQL ALTER TABLE

•ALTER TABLE: Modifies the structure of the existing


Employees table.
•ADD Salary DECIMAL(10, 2): Adds a new column
Salary of type decimal with up to 10 digits, including 2
after the decimal point
.

•Example
•Alter table Employees add salary int;
z
SQL TRUNCATE TABLE
To remove all records from the Employees table but
keep the table structure intact
:

Example
TRUNCATE TABLE Employees;
z
DML (Data Manipulation Language)

 DML (Data Manipulation Language) is a


subset of SQL (Structured Query Language)
used to manage and manipulate the data stored
within the database objects, such as tables. DML
commands are responsible for retrieving,
inserting, updating, and deleting data within the
database.
z
Common DML Commands:

•INSERT: Used to add new records into a table.


•UPDATE: Used to modify existing records in a
table.
•DELETE: Used to remove records from a table.
z
Example of insert

 INSERT INTO Employees VALUES (1, 'John', 'Doe',


'Software Engineer', 75000);
z
Updating Data in a Table:
If you need to update the Salary of the employee with EmployeeID =
1 to 80000:
UPDATE Employees
SET Salary = 80000
WHERE EmployeeID = 1;
z
Deleting Data from a Table:
 DELETE FROM Employees WHERE
EmployeeID = 1;
 If you want to delete all records from the
Employees table:
 DELETE FROM Employees;
z
Transaction Control Language (TCL)

COMMIT: Used to save all changes made in the


current transaction.
Example :COMMIT;
ROLLBACK: Used to undo changes made in the
current transaction
Example: ROLLBACK;
SAVEPOINT: Sets a savepoint within a transaction,
allowing partial rollbacks.
Example: SAVEPOINT Savepoint1;
z
Data Query Language (DQL)
primarily focuses on retrieving data from a database. The key
command in DQL is SELECT.
z
Selecting Data from a Table

 SELECT: Used to retrieve data from a database.

 SELECT * FROM Employees;

 SELECT *: Retrieves all columns.

 FROM Employees: Specifies the table from which to retrieve the


data.

 If you want to retrieve only the FirstName and Position of


employees:

 SELECT FirstName, Position FROM Employees;


z
Data Control Language (DCL)

Data Control Language (DCL) is used to manage


access to the database, specifically by controlling
who can access and manipulate the data within
the database. The main DCL commands are
GRANT and REVOKE.
z
1. GRANT
• Granting Privileges to a User:

• Purpose: Provides specific privileges to users or roles in the


database.

• Example:

• GRANT SELECT, INSERT ON Employees TO 'username’;

• Granting All Privileges:

• Example:

• GRANT ALL PRIVILEGES ON Employees TO 'admin';


z
REVOKE

•Purpose: Removes specific privileges from users or roles.


•Examples:
•Revoking Privileges from a User
REVOKE INSERT ON Employees FROM 'username';
This command revokes the INSERT privilege on the
Employees table from the user username.
Revoking All Privileges
REVOKE ALL PRIVILEGES ON Employees FROM 'admin';
This command revokes all privileges on the Employees table from
the admin user.
z
Privileges That Can Be Granted or Revoked
•SELECT: Allows the user to query data (read).
•INSERT: Allows the user to insert new data.
•UPDATE: Allows the user to update existing data.
•DELETE: Allows the user to delete data.
•EXECUTE: Allows the user to execute stored procedures.
•ALL PRIVILEGES: Grants all available privileges to the user.

You might also like