Unit4 Rdbms
Unit4 Rdbms
The RDBMS system manages the relational data. Oracle Database is the most
famous relational database system (RDBMS) because it shares the largest part of a
market among other relational databases. Some other popular relational databases
are MySQL, DB2, SQL Server, PostgreSQL, etc.
Oracle database
Oracle database is a relational database management system. It is also
called OracleDB, or simply Oracle. It is produced and marketed by Oracle
Corporation. It was created in 1977 by Lawrence Ellison and other engineers. It
is one of the most popular relational database engines in the IT market for storing,
organizing, and retrieving data.
Oracle database was the first DB that designed for enterprise grid computing and
data warehousing. Enterprise grid computing provides the most flexible and cost-
effective way to manage information and applications. It uses SQL queries as a
language for interacting with the database.
o Enterprise Edition: It is the most robust and secure edition. It offers all
features, including superior performance and security.
o Standard Edition: It provides the base functionality for users that do not
require Enterprise Edition's robust package.
o Express Edition (XE): It is the lightweight, free and limited Windows, and
Linux edition.
o Oracle Lite: It is designed for mobile devices.
Personal Edition: It's comparable to the Enterprise Edition but without the
Oracle Real Application Clusters feature.
Features
Oracle Database version 12.1, 12.2, 19c, and 21c support with converged database
capabilities enables you to run any database workload with all supported data types
Multilayered security including always-on transparent database encryption that
protects your databases at the source
Advanced database security and management technologies, such as Oracle Data
Safe, Data Masking Pack, Diagnostics Pack, and Tuning Pack, help you to meet
enterprise service level agreements
Fast provisioning of single-node virtual machine database systems for Oracle
Database with logical volume manager increases your developers’ productivity
Flexible and scalable Oracle Database license consumption allows you to meet
application needs while minimizing costs
Built-in automation increases your productivity by simplifying database lifecycle
management
Oracle Machine Learning, Graph, and Spatial features are included at no cost,
allowing developers to add innovative, in-database, analytic capabilities to existing
applications
Hybrid Columnar Compression reduces storage requirements for your data
warehouses
Oracle Database Zero Data Loss Autonomous Recovery Service simplifies data
protection and eliminates data loss exposure, providing low-cost resiliency against
ransomware attacks and human errors.
Bring-your-own-license (BYOL) subscriptions enable you to leverage existing
database licenses.
Oracle Database Personal Edition
Basically, with PE you can use all database features except for RAC,
RAC One Node and the DB Management Packs.
Oracle Database Express Edition (Oracle Database XE) is an entry-
level edition of Oracle Database that is quick to download, simple to
install and manage, and is free to develop, deploy, and distribute.
Oracle Database XE makes it easy to upgrade to the other editions of
Oracle without costly and complex migrations.
. Oracle Database XE can be installed on any size machine with any
number of CPUs, stores up to 4GB of user data, using up to 1GB of
memory, and using only one CPU on the host machine. Support is
provided by an online forum.
Oracle Database Personal Edition Oracle Database Personal Edition
supports single-user development and deployment environments that
require full compatibility with Oracle Database Standard Edition One,
Oracle Database Standard Edition, and Oracle Database Enterprise
Edition.
Personal Edition includes all of the components that are included with
Enterprise Edition, as well as all of the options that are available with
Enterprise Edition, with the exception of the Oracle Real Application
Clusters option, which cannot be used with Personal Edition. Personal
Edition is available on Windows platforms only. The Management
Packs are not included in Personal Edition.
Data types are used to represent the nature of the data that can be stored in the
database table. For example, in a particular column of a table, if we want to store a
string type of data then we will have to declare a string data type of this column.
Data types mainly classified into three categories for every database.
A list of data types used in MySQL database. This is based on MySQL 8.0.
MySQL String Data Types
CHAR(Size) It is used to specify a fixed length string that can contain numbers, letters, and special characters.
Its size can be 0 to 255 characters. Default is 1.
VARCHAR(Size) It is used to specify a variable length string that can contain numbers, letters, and special
characters. Its size can be from 0 to 65535 characters.
BINARY(Size) It is equal to CHAR() but stores binary byte strings. Its size parameter specifies the column length
in the bytes. Default is 1.
VARBINARY(Size) It is equal to VARCHAR() but stores binary byte strings. Its size parameter specifies the
maximum column length in bytes.
TEXT(Size) It holds a string that can contain a maximum length of 255 characters.
ENUM(val1, val2, val3,...) It is used when a string object having only one value, chosen from a list of possible values. It
contains 65535 values in an ENUM list. If you insert a value that is not in the list, a blank value
will be inserted.
SET( val1,val2,val3,....) It is used to specify a string that can have 0 or more values, chosen from a list of possible values.
You can list up to 64 values at one time in a SET list.
BLOB(size) It is used for BLOBs (Binary Large Objects). It can hold up to 65,535 bytes.
BIT(Size) It is used for a bit-value type. The number of bits per value is specified in size. Its size can be 1 to 64.
The default value is 1.
INT(size) It is used for the integer value. Its signed range varies from -2147483648 to 2147483647 and unsigned
range varies from 0 to 4294967295. The size parameter specifies the max display width that is 255.
FLOAT(size, It is used to specify a floating point number. Its size parameter specifies the total number of digits. The
d) number of digits after the decimal point is specified by d parameter.
FLOAT(p) It is used to specify a floating point number. MySQL used p parameter to determine whether to use
FLOAT or DOUBLE. If p is between 0 to24, the data type becomes FLOAT (). If p is from 25 to 53,
the data type becomes DOUBLE().
DOUBLE(size, It is a normal size floating point number. Its size parameter specifies the total number of digits. The
d) number of digits after the decimal is specified by d parameter.
DECIMAL(siz It is used to specify a fixed point number. Its size parameter specifies the total number of digits. The
e, d) number of digits after the decimal parameter is specified by d parameter. The maximum value for the
size is 65, and the default value is 10. The maximum value for d is 30, and the default value is 0.
DATE It is used to specify date format YYYY-MM-DD. Its supported range is from '1000-01-01' to '9999-12-31'.
DATETIME(fsp) It is used to specify date and time combination. Its format is YYYY-MM-DD hh:mm:ss. Its supported range is
from '1000-01-01 00:00:00' to 9999-12-31 23:59:59'.
TIMESTAMP(fsp It is used to specify the timestamp. Its value is stored as the number of seconds since the Unix epoch('1970-01-
) 01 00:00:00' UTC). Its format is YYYY-MM-DD hh:mm:ss. Its supported range is from '1970-01-01 00:00:01'
UTC to '2038-01-09 03:14:07' UTC.
TIME(fsp) It is used to specify the time format. Its format is hh:mm:ss. Its supported range is from '-838:59:59' to
'838:59:59'
YEAR It is used to specify a year in four-digit format. Values allowed in four digit format from 1901 to 2155, and
0000.
o SQL stands for Structured Query Language. It is used for storing and
managing data in relational database management system (RDMS).
o It is a standard language for Relational Database System. It enables a user to
create, read, update and delete relational databases and tables.
o All the RDBMS like MySQL, Informix, Oracle, MS Access and SQL Server
use SQL as their standard database language.
o SQL allows users to query the database in a number of ways, using English-
like statements.
Rules:
SQL process:
o When an SQL command is executing for any RDBMS, then the system
figure out the best way to carry out the request and the SQL engine
determines that how to interpret the task.
o In the process, various components are included. These components can be
optimization Engine, Query engine, Query dispatcher, classic, etc.
o All the non-SQL queries are handled by the classic query engine, but SQL
query engine won't handle logical files.
PL/SQL
PL/SQL tutorial provides basic and advanced concepts of SQL. Our PL/SQL tutorial is
designed for beginners and professionals.
PL/SQL is a block structured language that can have multiple blocks in it.
Our PL/SQL tutorial includes all topics of PL/SQL language such as conditional
statements, loops, arrays, string, exceptions, collections, records, triggers, functions,
procedures, cursors etc. There are also given PL/SQL interview questions and quizzes to
help you better understand the PL/SQL language.
SQL stands for Structured Query Language i.e. used to perform operations on the
records stored in database such as inserting records, updating records, deleting records,
creating, modifying and dropping tables, views etc.
What is PL/SQL
PL/SQL Functionalities
PL/SQL includes procedural language elements like conditions and loops. It allows
declaration of constants and variables, procedures and functions, types and variable
of those types and triggers. It can support Array and handle exceptions (runtime
errors). After the implementation of version 8 of Oracle database have included
features associated with object orientation. You can create PL/SQL units like
procedures, functions, packages, types and triggers, etc. which are stored in the
database for reuse by applications.
With PL/SQL, you can use SQL statements to manipulate Oracle data and flow of
control statements to process the data.
The PL/SQL is known for its combination of data manipulating power of SQL with
data processing power of procedural languages. It inherits the robustness, security,
and portability of the Oracle Database.
PL/SQL is not case sensitive so you are free to use lower case letters or upper case
letters except within string and character literals.
The DDL Commands in Structured Query Language are used to create and modify
the schema of the database and its objects. The syntax of DDL commands is
predefined for describing the data. The commands of Data Definition Language
deal with how the data should exist in the database.
1. CREATE Command
2. DROP Command
3. ALTER Command
4. TRUNCATE Command
5. RENAME Command
CREATE Command
CREATE is a DDL command used to create databases, tables, triggers and other
database objects.
Example 1: This example describes how to create a new database using the
CREATE DDL command.
Suppose, you want to create a Books database in the SQL database. To do this, you
have to write the following DDL Command:
Suppose, you want to create a Student table with five columns in the SQL
database. To do this, you have to write the following DDL command:
CREATE TABLE Student
(
Roll_No. Int ,
First_Name Varchar (20) ,
Last_Name Varchar (20) ,
Age Int ,
Marks Int ,
);
Example 3: This example describes how to create a new index using the CREATE
DDL command.
DROP Command
DROP is a DDL command used to delete/remove the database objects from the
SQL database. We can easily remove the entire table, view, or index from the
database using this DDL command.
Suppose, you want to delete the Books database from the SQL database. To do
this, you have to write the following DDL command:
Example 2: This example describes how to remove the existing table from the
SQL database.
Suppose, you want to delete the Student table from the SQL database. To do this,
you have to write the following DDL command:
ALTER Command
ALTER is a DDL command which changes or modifies the existing structure of
the database, and it also changes the schema of database objects.
We can also add and drop constraints of the table using the ALTER command.
Example 1: This example shows how to add a new field to the existing table.
Suppose, you want to add the 'Father's_Name' column in the existing Student table.
To do this, you have to write the following DDL command:
TRUNCATE Command
TRUNCATE is another DDL command which deletes or removes all the records
from the table.
This command also removes the space allocated for storing the table records.
Example
Suppose, you want to delete the record of the Student table. To do this, you have to
write the following TRUNCATE DDL command:
The above query successfully removed all the records from the student table. Let's
verify it by using the following SELECT statement:
RENAME is a DDL command which is used to change the name of the database
table.
Example
This query changes the name of the table from Student to Student_Details.
The DML commands in Structured Query Language change the data present in the
SQL database. We can easily access, store, modify, update and delete the existing
records from the database using DML commands.
1. SELECT Command
2. INSERT Command
3. UPDATE Command
4. DELETE Command
If we want to retrieve the data from all the columns of the table, we have to
use the following SELECT command:
Example 1: This example shows all the values of every column from the
table.
This SQL statement displays the following values of the student table:
BCA1001 Abhay 85
BCA1002 Anuj 75
BCA1003 Bheem 60
BCA1004 Ram 79
BCA1005 Sumit 80
Example 2: This example shows all the values of a specific column from
the table.
201 25000
202 45000
203 30000
204 29000
205 40000
Example 1: This example describes how to insert the record in the database table.
Let's take the following student table, which consists of only 2 records of the student.
101 Ramesh 92 20
201 Jatin 83 19
Suppose, you want to insert a new record into the student table. For this, you have to write the
following DML INSERT command:
1. INSERT INTO Student (Stu_id, Stu_Name, Stu_Marks, Stu_Age) VALUES (104, Anmol, 89,
19);
UPDATE DML Command
UPDATE is another most important data manipulation command in Structured Query Language,
which allows users to update or modify the existing data in database tables.
Here, 'UPDATE', 'SET', and 'WHERE' are the SQL keywords, and 'Table_name' is the name of
the table whose values you want to update.
Example 1: This example describes how to update the value of a single field.
P101 Chips 20 20
P102 Chocolates 60 40
P103 Maggi 75 5
P201 Biscuits 80 20
P203 Namkeen 40 50
Suppose, you want to update the Product_Price of the product whose Product_Id is P102. To do
this, you have to write the following DML UPDATE command:
Example 2: This example describes how to update the value of multiple fields of the
database table.
201 Jatin 83 19
202 Anuj 85 19
203 Monty 95 21
102 Saket 65 21
103 Sumit 78 19
104 Ashish 98 20
This command of Data Manipulation Language does not delete the stored data
permanently from the database. We use the WHERE clause with the DELETE
command to select specific rows from the table.
Example 1: This example describes how to delete a single record from the
table.
P101 Chips 20 20
P102 Chocolates 60 40
P103 Maggi 75 5
P201 Biscuits 80 20
P203 Namkeen 40 50
Suppose, you want to delete that product from the Product table whose Product_Id
is P203. To do this, you have to write the following DML DELETE command:
Example 2: This example describes how to delete the multiple records or rows
from the database table.
101 Ramesh 92 20
201 Jatin 83 19
202 Anuj 85 19
203 Monty 95 21
102 Saket 65 21
103 Sumit 78 19
104 Ashish 98 20
Suppose, you want to delete the record of those students whose Marks is greater
than 70. To do this, you have to write the following DML Update command:
SQL functions
Functions are methods used to perform data operations. SQL has many in-built
functions used to perform string concatenations, mathematical calculations etc.
1. Aggregate Functions
2. Scalar Functions
Function Description
SUM() Used to return the sum of a group of values.
Returns the number of rows either based on
COUNT()
a condition, or without a condition.
Used to calculate the average value of a
AVG()
numeric column.
This function returns the minimum value of
MIN()
a column.
MAX() Returns a maximum value of a column.
FIRST() Used to return the first value of the column.
This function returns the last value of the
LAST()
column.
Let us look into each one of the above functions in depth. For your better
understanding, I will be considering the following table to explain to you all the
examples.
SUM()
SELECT SUM(ColumnName)
FROM TableName;
Example:
Write a query to retrieve the sum of marks of all students from the Students table.
SELECT SUM(Marks)
FROM Students;
Output:
359
COUNT()
Returns the number of rows present in the table either based on some condition or
without any condition.
Syntax:
Example:
Write a query to count the number of students from the Students table.
SELECT COUNT(StudentID)
FROM Students;
Output:
Example:
Write a query to count the number of students scoring marks > 75 from the Students
table.
SELECT COUNT(StudentID)
FROM Students
WHERE Marks >75;
Output:
AVG()
Syntax:
SELECT AVG(ColumnName)
FROM TableName;
Example:
Write a query to calculate the average marks of all students from the Students
table.
SELECT AVG(Marks)
FROM Students;
Output:
71.8
MIN()
syntax:
SELECT MIN(ColumnName)
FROM TableName;
Example:
Write a query to retrieve the minimum marks out of all students from the Students table.
SELECT MIN(Marks)
FROM Students;
Output:
MAX()
Syntax:
Example:
Write a query to retrieve the maximum marks out of all students from the Students table.
SELECT MAX(Marks)
FROM Students;
Output:
FIRST()
This function returns the first value of the column which you choose.
Syntax:
SELECT FIRST(ColumnName)
FROM TableName;
Example:
SELECT FIRST(Marks)
FROM Students;
Output:
LAST()
Used to return the last value of the column which you choose.
Syntax:
SELECT LAST(ColumnName)
FROM TableName;
Example:
Well, with that we come to an end to SQL Aggregate Functions. Next in this article on
SQL Functions, let us understand the various Scalar Functions.
3.