Unit 8 DBMS
Unit 8 DBMS
NOTES OF LESSON
What is Database?
An organised group of data that is kept and accessible
electronically is referred to as a database. It is a digital
repository that enables the effective management, storage, and
retrieval of both organised and unorganised data. Information like
client records, financial data, inventory listings, and much more can
be stored in databases. Example of database are – Microsoft Access,
OpenOffice Base, Oracle, MySQL and PostgreSQL etc.
What is a Database Management System?
Data is stored, retrieved, and analyzed using software called
database management systems (DBMS). Users can create, read,
update, and remove data in databases using a Database
Management System, which acts as an interface between them and
the databases. Example of database Management System are –
Microsoft Access, OpenOffice Base, Oracle, MySQL and
PostgreSQL etc.
Data can be organized into two types:
• Flat File: Data is stored in a single table. Usually suitable for
less amount of data. basically for small-scale organization
where data does not need to be strucutred in a complex
way. Example of database software are Microsoft Excel or
Google Sheets.
• Relational: Data is stored in multiple tables and the tables are
linked using a common field. Relational is suitable for medium
to large amount of data. Example of database software are
MySQL, Microsoft SQL Server, and Oracle Database..
What is Database Server?
Database servers are dedicated computers that are designed to
store data and provide database services to other
computers. We use a database to store, organize, manage and
retrieve data efficiently and effectively. The database servers run
only database and database related software.
Advantages of Database
Reduces Data Redundancy
Data redundancy means when same data is stored more than one
places, which increased complexity and wasted of storage space, so,
database helps to reduce data redundacy.
Sharing of Data
A database allows its users to exchange data among themselves.
The data can only be shared with users who have received the
appropriate degrees of authorization because there are different
levels of access to the data.
Data Integrity
Data integrity refers to the accuracy and consistency of data
stored in a database management system (DBMS). Database
ensures that the data is reliable and can be trusted for decision
making and other critical business processes.
Data Security
A database’s concept of data security is important. The database
should only be accessible to authorised users, whose identities
must be verified using a username and password.
Privacy
The privacy rule in a database ensures that only authorized users
can access the database and view data according to the specific
privacy constraints. To maintain data security, access levels are set
in the database so that a user can only view data that they are not
allowed to modify if the permission is not given.
For example, in social networking sites, different accounts have
different access constraints, and users are only allowed to view the
other account data that is permitted for their specific account.
Backup and Recovery
Database Management System automaticlly take backup and
recovery processes to ensure the protection and availability of data.
This means that the DBMS automatically creates and manages
backups of the database at regular intervals, and also provides
tools to recover data in the event of a failure or data loss.
Data Consistency
Data consistency refers to the accuracy and reliability of data stored
in a database or other data storage system. It means that the data is
consistent and valid across all instances where it is stored or
accessed.
For example, if a customer’s name and address are stored in
multiple tables within a database, the data must be consistent across
all table.
Features of Database
There are some key features of a database:
1. One or more tables can be added in the database.
2. Decreased storage costs and space requirements
3. Users can use query languages in a database.
4. Multiple users can access the data from the database .
5. Unique keys aid in preventing errors caused by human or
technological mishaps.
Primary Key, Composite Primary Key and Foreign Key in a
Database
In the RDBMS data can be integrated using keys. These are Primary
Key, Composite Primary Key, and Foreign Key, Key are used to make
the relationship between the tables.
1. Primary Key – This unique field is called the Primary Key
(PK). primary key is a field or a set of fields that uniquely
identify each record in a table. A primary key must be unique
and cannot contain null values.
2. Composite Primary Key – A composite primary key is a
primary key that consists of two or more fields that together
uniquely identify each record in a table.
3. Foreign Key – A composite primary key is a primary key that
consists of two or more fields that together uniquely identify
each record in a table.
What is RDBMS?
A database management system that is based on the relational
model is called an RDBMS (Relation Database Management System).
Tables are used to organise data in relational databases. A relational
database management system (RDBMS) is used to store, manage,
query, and retrieve data.
Database Objects
a. Tables: Data is arranged into rows and columns in a table,
which is a type of data structure. It can be applied to both the
storage and presentation of structured data.
b. Columns or Fields or Attributes: Data is arranged vertically
from top to bottom in columns. Each row of the table has one
column, which is a collection of data values of a specific basic
type. The structure by which the rows are put together is
provided by the columns.
c. Rows or Records or Tuples: A row, also known as a Record or
Tuple, in a table represents a single data item. A database table
can be represented graphically as being made up of rows and
columns, or fields. Every row in a table has the same structure
and represents a group of connected data.
Difference between DBMS and RDBMS
Aspect DBMS RDBMS
Data is stored in various
Data is stored in tables that
formats such as flat files
Data structure or hierarchical are related to each other
using a relational model.
structures.
DBMS systems may or RDBMS systems enforce
Data integrity may not enforce strict strict data integrity rules that
data integrity rules. ensure data consistency and
Aspect DBMS RDBMS
accuracy.
Binary Types
For storing data in binary formats, binary data types are utilised. In
a database, binary data types can be used to store things like music
and image files. The binary data type can generally be used to store
files in any format.
Date Time
When specifying date and time values for a column used in a
database table, date time data types are used. Information like dates
of birth, admissions, product sales, and other dates can be stored in
databases using date and time data types.
Perform Operations on Table
In Base, data is kept in tables that may be added to, changed, or
deleted by using the proper options.
Insert Data in the Table
• Step 1 : Select the table > Double click on it
• Step 2 : The table will open in Datasheet View
• Step 3 : Now you can Insert Number of records in Datasheet
View
Editing Records in the Table
• Step 1 : Select the table > Double click on it.
• Step 2 : The table will open in Datasheet View
• Step 3 : Edit the record as per the requirement
Deleting Record From the Table
• Step 1 : Select the table > Double click on it.
• Step 2 : The table will open in Datasheet View
• Step 3 : Right click on data and select delete option
Field Properties
To modify the field’s attributes It is necessary to modify the table
structure in design view. The following actions will be taken to set
the field’s properties:
Select the table > Right click > Select the option Edit > the table
Design View window will open
Following are some properties of data of the numeric type:
1. AutoValue – if set to yes then field will get the auto numeric
values.
2. Length – By default length of the field is 10 but the size of the
field can be set to maximum length.
3. Default Value – A default value can be set for a field if user
don’t provide any value while entering the values in the table.
4. Format example – This property helps to set the format of the
data entered in the field such as 91-222-333.
Following are some properties of data of the character type:
1. Entry Required – if set to yes then it will be must to insert the
value in the field which means that field cannot be left blank.
2. Length – By default length of the field is 10 but the size of the
field can be set to maximum length.
3. Default Value – A default value can be set for a field if user
don’t provide any value while entering the values in the table.
4. Format example – This property helps to set the format of the
data entered in the field such as 91-222-333.
Sorting Data
Sorting means to arrange the data in either ascending order of
descending order. Sorting is the process of putting data into a
meaningful order so you can evaluate it more efficiently.
Referential Integrity
The relationship between tables is referred to as referential
integrity. Referential integrity is used to maintain accuracy and
consistency of data in a relationship. In Base, data can be linked
between two or more tables with the help of primary key and
foreign key constraints.
Referential integrity helps to avoid:
1. Adding records to a related table if there is no associated record
available in the primary key table.
2. Changing values in a primary if any dependent records are
present in associated table(s).
3. Deleting records from a primary key table if there are any
matching related records available in associated table(s).
Creating and Editing Relationships between Tables
An association or link between two or more tables is referred to as a
relationship. You don’t have to enter the same data again in different
tables when you relate two tables.
Relationships between tables helps to
1. Save time as there is no need to enter the same data in
separate tables.
2. Reduce data-entry errors.
3. Summarize data from related tables.
Type of Relationships in Database
There are three types of relationships which can be created in
tables:
1. ONE to ONE
2. ONE to MANY OR MANY to ONE
3. MANY to MANY
ONE to ONE
In this relationship, both the tables must have primary key columns.
ONE to MANY OR MANY to ONE
In this relationship, one of the table must have primary key column.
It signifies that one column of primary key table is associated with
all the columns of associated table.
MANY to MANY
In this relationship, no table has the primary key column. It signifies
that all the columns of primary key table are associated with all the
columns of associated table.
Note Removing the Relationships – With the use of the Delete
option, the relationships that have been applied to the tables can
also be deleted. When you right-click a relationship thread, the
Delete option will appear.
Retrieve Data using Query
In order to describe the data structure and to modify the data in the
database, queries are used as instructions. A query enables the
joining and filtering of data from various tables.
Database Languages having two type:
1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)
DDL Statements:
• Create: Using this statement, a database or set of tables can be
created.
• Alternate: This statement is used to change the table’s
structure.
• Drop: This statement is used to remove database objects from
the system.
DML statements:
• SELECT: The statement “SELECT” is used to get data from the
database.
• INSERT: The statement “INSERT” is used to add a new record
to the database.
• DELETE: The database can be cleaned out by using the
statement DELETE.
• UPDATE: This statement is used to modify the database’s
information.
Database Query
Query is a computer languages. In order to describe the data
structure and to modify the data in the database, queries are used as
instructions. Query can extract particular data from a database. We
can filter and join data from various tables with the help of a query.
By using the criteria you supply query will filter the data.
Select Statement
A select query is a language in a database that displays data in
Datasheet view. Data from tables is displayed by a query rather than
being stored by it. A query may display data from one or more
tables, from other queries, or from both of these sources
simultaneously.
The SELECT statement has many optional clauses:
• WHERE specifies which rows to retrieve.
• ORDER BY specifies an order in which to return the rows.
Syntax of Select Statement is –
SELECT * FROM <TABLENAME>;
Query related to Simple Select Statement –
Table Name – product
Product_No Product_Name Price Quantity
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
52 Soap Box 120 100
Question – Write a Query to display all record from the table;
Soap 40
Powder 80
Shampoo 300
25 Soap 40 80
31 Powder 80 30
45 Shampoo 250 25
25 Soap 40 80
31 Powder 80 30
Question – Write a Query to find the total amount of the Shampoo
product;
Select Price*Quantity from product where Product_Name =
‘Shampoo’;
Output – 6250
Or
Select Product_No, Product_Name, Price*Quantity from product
where Product_Name = 'Shampoo';
Output –
Product_No Product_Nam Price*Quantity
45 Shampoo 6250
Question – Write a Query to display the data whose quantity is
equal to 80.
Select * from product where quantity = 80;
Output –
Product_No Product_Nam Price Quantity
25 Soap 40 80