0% found this document useful (0 votes)
5 views55 pages

Database Management System

Dbms

Uploaded by

dikshantsapkota9
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)
5 views55 pages

Database Management System

Dbms

Uploaded by

dikshantsapkota9
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
You are on page 1/ 55

Chapter 1

Database
Management
System
Success Shrestha
Data Information
 Facts and statistics collected together for  Facts provided or learned about something or
reference or analysis someone
 Datas can be on paper, or computer  Information is an obtained by processing
 In computer, data are stored in folders data

 Data can be image, text, audio or videp  Information can be obtained by


investagation, research, study or instruction

DATA Processing INFORMATION

7/28/2022 Annual Review 2


Database
• Organized collection of structured information, or data,
typically stored electronically in a computer system
• Is systematic collection of data
• Data in database are related data
• Phone directory, Library Booklist and so on
• We can filter data in database and pick chosen one

7/28/2022 Annual Review 3


Database Management System (DBMS)

• Is a software package designed to define, manipulate, retrieve and manage data in a database
• Generally manipulates the data itself, the data format, field names, record structure and file
structure
• Computerized data-keeping system
• There are variety of software such as MySQL, SQL, Oracle, Sqlite, MS access and so on

7/28/2022 Annual Review 4


Basic things of Database
• Table
• Field
• Records
• Object
• File
• Key
• Primary Keys
• Alternative Keys
• Candidate keys
• Foreign keys

7/28/2022 Annual Review 5


Database Table
• Database table is composed of records and fields which hold data
• Data is logically organized in a row-and-column format similar to a spreadsheet
• In database table similar kind of data are stored
• Each row represents a unique record, and each column represents a field in the record

SN. Name Address Stream Percentage Remarks


1 Hari Bahadur Machapokhari Management 78% Distinction
2 Ram Bahadur Lainchour Science 82% Distinction
3 Shyam Bahadur Thapathali Law 68% First Division

7/28/2022 Annual Review 6


Database Field
• Field is a data structure for a single piece of data
• Fields are organized into records, which contain all the information within the table relevant to a specific
entity
• A column is a collection of cells aligned vertically in a table

SN. Name Address Stream Percentage Remarks


1 Hari Bahadur Machapokhari Management 78% Distinction
2 Ram Bahadur Lainchour Science 82% Distinction
3 Shyam Bahadur Thapathali Law 68% First Division

7/28/2022 Annual Review 7


Database Records
• Is a group of fields within a table that are relevant to a specific entity or similar entry
• A row is data record within a table
• Each row, represents a complete record of specific item data, holds different data within the same structure

SN. Name Address Stream Percentage Remarks


1 Hari Bahadur Machapokhari Management 78% Distinction
2 Ram Bahadur Lainchour Science 82% Distinction
3 Shyam Bahadur Thapathali Law 68% First Division

7/28/2022 Annual Review 8


Database Object
• Is a data structure used to either store or reference data
• Database objects can be made using the create command
• These database objects are used for holding and manipulating the data in the database
• Some database objects are
• View: subsets of data from more than one table are logically represented.
• Table: composed of rows and columns, the table is the primary form of data representation.
• Sequence: sequence generates the primary key values.
• Synonym: it is an alternative name for a specific object.
• Index: it improves the performance of some particular queries.

7/28/2022 Annual Review 9


KEYS
• A key in DBMS is an attribute or a set of attributes that help to uniquely identify a tuple (or row) in a relation
(or table)
• Keys are also used to establish relationships between the different tables and columns of a relational
database
• Types of keys are:
• Primary Keys
• Foreign Keys
• Associative Keys

7/28/2022 Annual Review 10


Foreign Keys
• A foreign key is the one that is used to link two tables together via the primary key
• A foreign key is a set of attributes that references a candidate key

SID Regd_ID Name Stream Grade Regd_ID Name

1 701123 Process Shrestha Management A 701120 Krishna Shah


701121 Lalu Lal Shrestha
2 701124 Sanyukta Maharjan Management A
701122 Nikesh Lama
3 701125 Suraj Maharjan Science A+ 701123 Process Shrestha
6 701128 Tika Nepal Law B
701124 Sanyukta Maharjan

7/28/2022 Annual Review 11


Alternate Keys
• In database, it is a column which uniquely identifies every rows in that table
• The key that has not been selected to be the primary key, but are candidate keys
• An alternate key is a column or group of columns that uniquely identify every row in a table

SID Regd_ID Name Stream Grade


1 701123 Process Shrestha Management A
2 701124 Sanyukta Maharjan Management A
3 701125 Suraj Maharjan Science A+
6 701128 Tika Nepal Law B

7/28/2022 Annual Review 12


Advantages of DBMS
• Improved data sharing
• Improved data security
• Data integration
• Improved decision making
• Reduction of redundancy
• Providing backups

7/28/2022 Annual Review 13


Disadvantage of DBMS
• Cost
• Complexity
• Technical Staff required
• Database failure
• Extra cost of hardware
• Providing backup and Recovery

7/28/2022 Annual Review 14


DDL

• Data Definition Language (DDL) is a subset of SQL


• A data definition language (DDL) is a computer language used to create and modify the structure of
database objects in a database.
• DDL commands can be used to add, remove, or modify tables within in a database
• DDL commands are used for altering the database structure such as creating new tables or objects along
with all their attributes (data type, table name, etc.)
• Some DDL commands are Create, Alter, Drop, Truncate

7/28/2022 Annual Review 15


Create
• Create query is used to create any new database or table in database
• To create new database
• Syntax: CREATE DATABASE database_name;
• Example CREATE DATABASE KCCS; [It creates new database named KCCS]
• To create a new table
• syntax : CREATE TABLE tableName( column 1 datatype,
column 2 datatype,
column 3 datatype
<integrity constraints>
);
• Example : CREATE TABLE studentInto( id int,
name varchar(30),
address varchar(30),
phone_number numeric(10,0),
PRIMARY KEY(id)
); [ It created new table named studentInfo where we can insert data after onwards]
• Once we created database or table we can use the same name to another
7/28/2022 Annual Review 16
ALTER
• An alter command modifies an existing database table
• This command can add up additional column, drop existing columns and
even change the data type of columns involved in a database table
• Syntax ALTER TABLE tableName ADD attributeName(column name)
datatype;
• ALTER TABLE studentInfo ADD stream varchar(30);
• Note : After that a new column in studentInfo table is added and we
can insert more data

7/28/2022 Annual Review 17


DROP
• A drop command is used to delete objects such as a table, index or view
• A DROP statement cannot be rolled back, so once an object is destroyed, there’s no
way to recover it
• DROP TABLE table_name;
• DROP TABLE studentInfo;
• Note: When we use drop syntax then existing table gets delete and we can’t recover it

7/28/2022 Annual Review 18


TRUNCATE
• Similar to DROP, the TRUNCATE statement is used to quickly remove all records from a
table
• DROP that completely destroys a table, TRUNCATE preserves its full structure to be
reused later.
• TRUNCATE TABLE studentInfo;
• Note : It will make an empty table so we can insert data in future

7/28/2022 Annual Review 19


DML

• A data manipulation language (DML) is a computer programming


language used for adding (inserting), deleting, and modifying
(updating) data in a database
• DML resembles simple English language and enhances efficient user
interaction with the system
• The functional capability of DML is organized in manipulation
commands like SELECT, UPDATE, INSERT INTO and DELETE
FROM database

7/28/2022 Annual Review 20


Select Statement
• This command is used to retrieve rows from a table
• Syntax SELECT [column name(s)] from [table name] WHERE [conditions]
• SELECT is the most widely used DML command in SQL
• SELECT name, address, phoneNumber from studentInfo WHERE
address=‘Machhaphokari’;
• Note : Now form studentInfo only column of name, address, phoneNumber are selected
and all data of address machaphokari is listed

7/28/2022 Annual Review 21


INSERT STATEMENT
• This command adds one or more records to a database table
• Syntax is INSERT INTO [table name] [column(s)] VALUES [value(s)]
• INSERT INTO studentInfo (id, name, address, phoneNumber) VALUES (7, Process,
Balaju, 9843068916);
• Note : Now in studentInfo table one row will be added of these values

7/28/2022 Annual Review 22


Update Statement
• This command modifies data of one or more records
• Syntax is UPDATE [table name] SET [column name = value] where [condition]
• UPDATE studentInfo SET (phoneNumber = 9813765964) WHERE id = 7;
• Note : Now in studentInfo table id 7 phonenumber will be changed to new number

7/28/2022 Annual Review 23


Delete Statement
• This command removes one or more records from a table according to specified conditions
• Syntax is DELETE FROM [table name] where [condition]
• DELETE FROM studentInfo WHERE id = 7;
• Note : Now in studentInfo table id no 7 will be deleted

7/28/2022 Annual Review 24


DATABASE MODEL
• Database model is a type of data model that determines the logical structure of a
database
• It fundamentally determines in which manner data can be stored, organized and
manipulated
• Used to represent the data and how it is stored in the database and to set the
relationship between data items
• Its types
• Hierarchical Model
• Network Model
• Relational Database Model

7/28/2022 Annual Review 25


HIERARCHICAL DATABASE MODEL

• Hierarchical database model resembles a tree structure, similar to a folder


architecture in your computer system
• The relationships between records are pre-defined in a one to one manner,
between 'parent and child' nodes
• They require the user to pass a hierarchy in order to access needed data

7/28/2022 Annual Review 26


HIERARCHICAL DATABASE MODEL
Advantage Disadvantage
• The model allows you to easily add and • Even though this model is conceptually
delete new information. simple and easy to design at the same
• Data at the top of the hierarchy can be time it is quite complex to implement
accessed quickly. • It has no standards as the
• This model works well with linear data implementation of this model does not
storage mediums such as tapes. provide any specific standard
• This model also lacks flexibility as the
changes in the new tables or segments

7/28/2022 Annual Review 27


NETWORK DATA MODEL
• This model was formalized by the Database
Task group in the 1960s
• This model is the generalization of the
hierarchical model
• This model can consist of multiple parent
segments and these segments are grouped as
levels but there exists a logical association
between the segments belonging to any level
• There exists a many-to-many logical
association between any of the two segments

7/28/2022 Annual Review 28


NETWORK DATA MODEL
Advantage Disadvantage
• This model is very simple and easy to • The schema or the structure of this
design like the hierarchical data model. database is very complex in nature as all
• This model is capable of handling the records are maintained by the use of
multiple types of relationships which can pointers
help in modelling real-life applications, • The design or the structure of this model
for example, 1: 1, 1: M, M: N is not user-friendly
relationships.
• This model does not have any scope of
 This network does not allow a member automated query optimization
to exist without an owner which leads to
the concept of Data integrity.

7/28/2022 Annual Review 29


RELATIONAL DATA MODEL
• Relational Model was proposed by E.F. Codd
to model data in the form of relations or tables
• A common type of database that stores data in
tables, so it can be used in relation to other
stored datasets
• A relational database stores data in the form
of relations (tables)

7/28/2022 Annual Review 30


NETWORK DATA MODEL
Advantage Disadvantage
 Very less redundancy of data in this model  Very complex designs are made
 Normalization of database is possible in this (ER–diagram, schema diagram)
model  We got many rule to prepare data table
 Quick data processing so its not user friendly

 Table are interlinked with some common  Expensive to make and need extra
keys storage

 We bind our database by various level of


security

7/28/2022 Annual Review 31


Centralized Database
• A centralized database (sometimes abbreviated CDB) is a database that is located,
stored, and maintained in a single location
• Users access a centralized database through a computer network which is able to
give them access to the central CPU, which in turn maintains to the database itself
• Mainframe computer is the example of centralized database management system

7/28/2022 Annual Review 32


Centralized Database
Advantage Disadvantage
 It allows for working on cross-functional  It can become unresponsive to the
projects needs of the business
 It is easier to share ideas across analysts  It can have a negative impact on local
 Higher levels of dependability are morale
present within the system  It may increase costs
 Organizations can act with greater speed  There is a risk of loss
 t helps an organization stay close to a
focused vision

7/28/2022 Annual Review 33


Distributed Database
• A distributed database is a collection of
multiple, logically interrelated databases
distributed over a computer network
• Database that is not limited to one system, it
is spread over different sites
• Distributed databases allow local users to
manage and access the data in the local
databases while providing some sort of
global data management which provides
global users with a global view of the data

7/28/2022 Annual Review 34


Distributed Database
Advantage Disadvantage
 Modular Development( Plant on  Cost( More the server more expensive
various location) it becomes)
 More Reliable( If one crashes another  Security( Very hard to save our data)
is running)
 Database design more complex( Our
 Better Response( Faster to locate due data are fragmented and stored)
to regional servers)
 More difficult to handle ( We may get
 Lower Communication Cost (Regional some threats )
Server helps to communication cost
on cheaper way)
 Improved share ability and local
autonomy
7/28/2022 Annual Review 35
Difference Between Centralized and Distributed Database
Centralized database Distributed database

It is a database which consists of multiple databases which are


It is a database that is stored, located as well as maintained at
1. connected with each other and are spread across different physical
a single location only.
locations.

The data access time in the case of multiple users is more in a The data access time in the case of multiple users is less in a
2.
centralized database. distributed database.

The management, modification, and backup of this database The management, modification, and backup of this database are very
3.
are easier as the entire data is present at the same location. difficult as it is spread across different physical locations.

This database provides a uniform and complete view to the Since it is spread across different locations thus it is difficult to
4.
user. provide a uniform view to the user.

This database has more data consistency in comparison to This database may have some data replications thus data consistency
5.
distributed database. is less.

The users cannot access the database in case of database In distributed database, if one database fails users have access to other
6.
failure occurs. databases.

7. Centralized
7/28/2022
database is less costly.
Annual Review
This database is very expensive. 36
Database Security
• Database security refers to the range of tools, controls, and measures
designed to establish and preserve database confidentiality, integrity,
and availability
• Database security procedures are aimed at protecting not just the
data inside the database, but the database management system and
all the applications that access it from intrusion, misuse of data, and
damage
• Database security is generally planned, implemented and maintained
by a database administrator and or other information security
professional
• We use various encryption technique to make our database more
secure and phishing can be avoided

7/28/2022 Annual Review 37


Importance of Database Security
• Compromised intellectual property
• Damage to brand reputation
• Business continuity
• Costs of repairing breaches and notifying customers

7/28/2022 Annual Review 38


Some Challenges on Database Security
• Insider threats
• Human error
• Exploitation of database software vulnerabilities
• Buffer overflow exploitations
• Denial of service (DoS/DDoS) attacks
• Malware

7/28/2022 Annual Review 39


Security Measured at several Level
• Database System Level (Allowing Access of DBMS)
• Operating System Level (Login Credentials and roles)
• Network Level (Website Security)
• Physical Level (Locking by lock door windows, earthquake and other)
• Human Level (Finger Lock and choosing best security)

7/28/2022 Annual Review 40


NORMALIZATION
• Normalization is the process of minimizing redundancy from a relation or set of relations
• It also eliminates redundancy and increases the integrity which improves performance of the query
• Organizing non structured data in to structured data
• Normalization is used for mainly two purposes,
• Eliminating redundant(useless) data.
• Ensuring data dependencies make sense i.e. data is logically stored.
• 1NF : Makes all table in an atomic values
• 2NF : The relation in second normal form is also in first normal form and no partial dependencies on any
column in primary key
• 3NF : Be in 2NF and Has no transitive functional dependencies and To move our 2NF table into 3NF, we
again need to again divide our table

7/28/2022 Annual Review 41


Advantage of Normalization
1. It eliminates data redundancy i.e. duplication of data.
2. It enhances faster sorting and index creation.
3. It simplifies the complex structure of tables.
4. It avoid loss of data through consistency and integrity.
5. It solves insertion, deletion and updating anomalies.
6. It improves the performance of a system.

7/28/2022 Annual Review 42


Un Normalized Table
Employee_table

7/28/2022 Annual Review 43


1NF
• Now we make our data attributes atomic i.e. we don’t have double data for a single values
Employee_table

• Now each Name has an separate department in our database


• By this we make our data values atomic
• But there is still data redundancy so we move to next step
7/28/2022 Annual Review 44
2NF
• We introduce primary keys and secondary keys in our database
• WE make two separate tables and link them by primary and foreign keys
• We try to remove functional dependency
Employee_ info _table Employee_with_department_table

• Since department, age , address depends upon name


• So we create new table where we create an department list table with department assignment and Employee
Detail Table
• But we got a problem (if we delete any one of Employee Detail then Department will be also delete

7/28/2022 Annual Review 45


3NF
• Now we make one more extra table to overcome some functional dependency and data lost
• We add one more table in which we give code to our department and link with primary and secondary keys

• Now if anyone of employee left then our data of department wont be lost because we got separate table
where we store our department lists
• We don’t have transitive functional dependency
7/28/2022 Annual Review 46
DBA (Database Administrator)
• Is a specialist person who manages, maintain and secure
data in database
• DBA manage overall data in database environment
• DBA is database expert who implement and configure all
database in any organization
• DBA monitor all query and s/he so that there wont be any
illegal access in our database

7/28/2022 Annual Review 47


Responsibilities of DBA
• Monitoring System
• Planning and allocating physical requirements
• Monitor technical support
• Creating Backup and recovery
• Modifying database structure
• Monitoring and optimizing database server
• Creating user profile and allowing access
• Creating database reports

7/28/2022 Annual Review 48


Characteristics of DBA
• Analytical Skills
• Communication Skills
• Data structure of organization
• Problem-solving skills
• Logical Thinking or Critical Thinking
• Expert in database and query

7/28/2022 Annual Review 49


Some terminology in Database
• Data Dictionary
• Relational Database management
• ER model
• Metadata
• Data Integrity

7/28/2022 Annual Review 50


Data Dictionary
• A Data Dictionary is a collection of names, definitions, and attributes about data elements that are
being used or captured in a database, information system, or part of a research project
• It makes easy for analyst to understand data records and give a quick decision
• It have information about database tables, how they stored, dependency of keys
• Contains records about other objects in the database, such as data ownership, data relationships to
other objects, and other data
• crucial component of any relational database

7/28/2022 Annual Review 51


ER Diagram
• Describes the structure of a database with the help of a diagram
• ER model is a design or blueprint of a database that can later be implemented as a database
• They use a defined set of symbols such as rectangles, diamonds, ovals and connecting lines to depict
the interconnectedness of entities, relationships and their attributes

7/28/2022 Annual Review 52


Metadata
• A collection of information like the author, file size, the date the document was created, and keywords to
describe the document.
• Structured reference data that helps to sort and identify attributes of the information it describes

7/28/2022 Annual Review 53


Relational Database Management System

• In relational database management system data are stored in table format


• Data access can be fast and efficient
• Table are linked with each other by various keys
• Database can be distributed by giving various access levels
• Duplicate data can be omitted

7/28/2022 Annual Review 54


Difference between RDBMS and DBMS
Relational Database Management System Database Management System
Data stored is in table format Data stored is in the file format
Multiple data elements are accessible together Individual access of data elements
Data in the form of a table are linked together No connection between data
Normalization is not achievable There is normalization
Support distributed database No support for distributed database
Data is stored in a large amount Data stored is a small quantity
Here, redundancy of data is reduced with the help of key Data redundancy is common
and indexes in RDBMS
RDBMS supports multiple users DBMS supports a single user
It features multiple layers of security while handling data There is only low security while handling data
The software and hardware requirements are higher The software and hardware requirements are low

7/28/2022 Annual Review 55

You might also like