DBMS

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 19

Ch.

– 2 Introduction to DBMS
Definition of a Database, RDBMS
 A database is a collection of information that is organized so that it can be easily
accessed, managed and updated. Computer databases typically contain
aggregations of data records or files, containing information about sales
transactions or interactions with specific customers.

 In a relational database, digital information about a specific customer is


organized into rows, columns and tables which are indexed to make it easier to
find relevant information through SQL or No SQL queries. In contrast, a graph
database uses nodes and edges to define relationships between data entries and
queries require a special semantic search syntax.
Introduction to Database
 A database is an organized collection of data, generally stored and
accessed electronically from a computer system. Where databases are
more complex they are often developed using formal design and
modeling techniques.

 The database management system (DBMS) is the software that interacts


with end users, applications, and the database itself to capture and
analyze the data. The DBMS software additionally encompasses the core
facilities provided to administer the database. The sum total of the
database, the DBMS and the associated applications can be referred to as
a "database system". Often the term "database" is also used to loosely
refer to any of the DBMS, the database system or an application
associated with the database.
 Examples of popular DBMS are – MySQL, PostgreSQL, Access, Oracle,
SQL Server, IBM, DB2 and Sybase.
Applications of DBMS
Sector Use of DBMS

Banking For customer information, account activities, payments,


deposits, loans, etc.

Airlines For reservations and schedule information.

Universities For student information, course registrations, colleges and


grades.

Telecommunication It helps to keep call records, monthly bills, maintaining


balances, etc.

Finance For storing information about stock, sales, and purchases


of financial instruments like stocks and bonds.

Sales Use for storing customer, product & sales information.

Manufacturing It is used for the management of supply chain and for


tracking production of items. Inventories status in
warehouses.

HR Management For information about employees, salaries, payroll,


deduction, generation of paychecks, etc.
Advantages of DBMS
 DBMS offers a variety of techniques to store & retrieve data
 DBMS serves as an efficient handler to balance the needs of multiple
applications using the same data
 Uniform administration procedures for data
 Application programmers never exposed to details of data representation and
storage.
 A DBMS uses various powerful functions to store and retrieve data efficiently.
 Offers Data Integrity and Security
 The DBMS implies integrity constraints to get a high level of protection against
prohibited access to data.
 A DBMS schedules concurrent access to the data in such a manner that only one
user can access the same data at a time
 Reduced Application Development Time
Data Model
 Data models define how the logical structure of a database is
modeled. Data Models are fundamental entities to introduce abstraction
in a DBMS. Data models define how data is connected to each other and
how they are processed and stored inside the system.
 Relational Model
 The most popular data model in DBMS is the Relational Model. It is more
scientific a model than others. This model is based on first-order predicate
logic and defines a table as an n-ary relation.
 See image in next slide.
 The main highlights of this model are −
 Data is stored in tables called relations.
 Relations can be normalized.
 In normalized relations, values saved are atomic values.
 Each row in a relation contains a unique value.
 Each column in a relation contains values from a same domain.
Properties of transaction/ ACID property.
 A transaction is a very small unit of a program and it may contain several lowlevel tasks. A
transaction in a database system must maintain Atomicity, Consistency, Isolation, and Durability −
commonly known as ACID properties − in order to ensure accuracy, completeness, and data
integrity.
 Atomicity: This property ensures that either all the operations of a transaction reflect in database or
none. Let’s take an example of banking system to understand this: Suppose Account A has a balance
of 400$ & B has 700$. Account A is transferring 100$ to Account B. This is a transaction that has two
operations a) Debiting 100$ from A’s balance b) Creating 100$ to B’s balance. Let’s say first operation
passed successfully while second failed, in this case A’s balance would be 300$ while B would be
having 700$ instead of 800$. This is unacceptable in a banking system. Either the transaction should
fail without executing any of the operation or it should process both the operations. The Atomicity
property ensures that.
 Consistency: To preserve the consistency of database, the execution of transaction should take place
in isolation (that means no other transaction should run concurrently when there is a transaction
already running). For example account A is having a balance of 400$ and it is transferring 100$ to
account B & C both. So we have two transactions here. Let’s say these transactions run concurrently
and both the transactions read 400$ balance, in that case the final balance of A would be 300$ instead
of 200$. This is wrong. If the transaction were to run in isolation then the second transaction would
have read the correct balance 300$ (before debiting 100$) once the first transaction went successful.
 Isolation: For every pair of transactions, one transaction should start
execution only when the other finished execution. I have already
discussed the example of Isolation in the Consistency property above.
 Durability: Once a transaction completes successfully, the changes it has
made into the database should be permanent even if there is a system
failure. The recovery-management component of database systems
ensures the durability of transaction.
Relationships in database:
 A relationship, in the context of databases, is a situation that exists
between two relational database tables when one table has a foreign key
that references the primary key of the other table. Relationships allow
relational databases to split and store data in different tables, while
linking disparate data items.
 One-to-One
 A row in table A can have only one matching row in table B, and vice
versa.
 This is not a common relationship type, as the data stored in table B could just have easily
been stored in table A. However, there are some valid reasons for using this relationship
type. A one-to-one relationship can be used for security purposes, to divide a large table,
and various other specific purposes.
 In the above example, we could just as easily have put an HourlyRate field straight into
the Employee table and not bothered with the Pay table. However, hourly rate could be
sensitive data that only certain database users should see. So, by putting the hourly rate
into a separate table, we can provide extra security around the Pay table so that only
certain users can access the data in that table.
 One-to-Many (or Many-to-One)
 This is the most common relationship type. In this type of relationship, a row in table A
can have many matching rows in table B, but a row in table B can have only one matching
row in table A.
One-to-Many relationships can also be viewed as Many-to-One
relationships, depending on which way you look at it.
In the above example, the Customer table is the “many” and the City
table is the “one”. Each customer can only be assigned one city,. One
city can be assigned to many customers.

Many-to-Many

In a many-to-many relationship, a row in table A can have many


matching rows in table B, and vice versa.
A many-to-many relationship could be thought of as two one-to-many
relationships, linked by an intermediary table.
The intermediary table is typically referred to as a “junction table”
(also as a “cross-reference table”). This table is used to link the other
two tables together. It does this by having two fields that reference
the primary key of each of the other two tables.
The following is an example of a many-to-many relationship:
So in order to create a many-to-many relationship between the Customers table and the Products
table, we created a new table called Orders.
In the Orders table, we have a field called CustomerId and another called ProductId. The values that
these fields contain should correspond with a value in the corresponding field in the referenced table.
So any given value in Orders.CustomerId should also exist in the Customer.CustomerId field. If this
wasn’t the case then we could have orders for customers that don’t actually exist. We could also have
orders for products that don’t exist. Not good referential integrity.
Most database systems allow you to specify whether the database should enforce referential integrity.
So, when a user (or a process) attempts to insert a foreign key value that doesn’t exist in the primary
key field, an error will occur.
In our example, Orders.CustomerId field is a foreign key to the Customers.CustomerId (which is the
primary key of that table). And the Orders.ProductId field is a foreign key to the Products.ProductId
field (which is the primary key of that table).
 Introduction to RDBMS
 RDBMS stands for relational database management system. A relational model can be represented as a table
of rows and columns. A relational database has following major components:
1. Table
2. Record or Tuple
3. Field or Column name or Attribute
4. Keys
 A table is a collection of data represented in rows and columns. Each table has a name in database. For
example, the following table “STUDENT” stores the information of students in database.
 Table :- Student

Student_Id Student_Name Student_Addr Student_Age


Dayal Bagh,
101 Chaitanya 27
Agra
102 Ajeet Delhi 26
103 Rahul Gurgaon 24
104 Shubham Chennai 25
 Record or Tuple
 Each row of a table is known as record. It is also known as tuple. For example, the following row is a
record that we have taken from the above table.

102 Ajeet Delhi 26

. Field or Column name or Attribute


The above table “STUDENT” has four fields (or attributes): Student_Id, Student_Name,
Student_Addr & Student_Age.

Types of keys in DBMS

Primary Key – A primary is a column or set of columns in a table that uniquely identifies tuples
(rows) in that table.

Foreign Key – Foreign keys are the columns of a table that points to the primary key of another
table. They act as a cross-reference between tables.
 Introduction to SQL
 Structure Query Language(SQL) is a database query language used for storing and managing data in Relational
DBMS. SQL was the first commercial language introduced for E.F Codd's Relational model of database. Today
almost all RDBMS(MySql, Oracle, Infomix, Sybase, MS Access) use SQL as the standard database query language.
SQL is used to perform all types of data operations in RDBMS.
 SQL Command
 DDL: Data Definition Language
 This includes changes to the structure of the table like creation of table, altering table, deleting a table etc.
 All DDL commands are auto-committed. That means it saves all the changes permanently in the database.

Command Description
create to create new table or database
alter for alteration
truncate delete data from table
drop to drop a table
rename to rename a table
 DML: Data Manipulation Language
 DML commands are used for manipulating the data stored in the table and not the table itself.
 DML commands are not auto-committed. It means changes are not permanent to database, they can be
rolled back.

Command Description
insert to insert a new row
update to update existing row
delete to delete a row
merge merging two rows or two
tables
 DCL: Data Control Language
 Data control language are the commands to grant and take back authority from any
database user.

Command Description
grant grant permission of right
revoke take back permission.

You might also like