Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

DATA DEFINITION LANGUAGE (DDL):

1. CREATE: It is used to create a new table in the database.


Syntax: CREATE TABLE table_name (column_name datatype[size]);
Example: CREATE TABLE employee (Name VARCHAR2(20), Email VARCHAR2(100),
DOB DATE);

2. ALTER: It is used to alter the structure of the database. This change could be either
to modify the characteristics of an existing attribute or probably to add a new
attribute.
Syntax:
To add a new column in the table:
ALTER TABLE table_name ADD column_name (column-definition);
To modify existing column in the table: ALTER TABLE table_name MODIFY
(column_definition);
Example:
ALTER TABLE stu_details ADD (address VARCHAR2(20));
ALTER TABLE stu_details MODIFY (name VARCHAR2(20));

3. DROP: It is used to delete both the structure and the records stored in the table.
Syntax: DROP TABLE table_name;
Example: DROP TABLE employee;

4. TRUNCATE: It is used to delete all the rows from the table and free the space
containing the table.
Syntax: TRUNCATE TABLE table_name;
Example: TRUNCATE TABLE employee;

5. RENAME: It is used to change the name of the database table.


Syntax: RENAME old_table_name TO new_table_name;
Example: RENAME Student TO Student_details;
6. DESCRIBE: It is used to describe the list of column definitions for specified table.
Syntax: DESC table_name;
Example: DESC student;

DATA MANIPULATION LANGUAGE (DML):


1. INSERT: The INSERT statement is used to insert data into the row of a table.
Syntax: INSERT INTO TABLE_NAME (col1, col2, col3, .... col N)
VALUES (value1, value2, value3, .... valueN);
Example: INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");

2. UPDATE: This command is used to update or modify the value of a column in the
table.
Syntax: UPDATE table_name SET column_name1= value1 WHERE [condition];
Example: UPDATE students SET User_Name = 'Sonoo'
WHERE Student_Id = '3';

3. DELETE: It is used to remove one or more row from a table.


Syntax: DELETE FROM table_name [WHERE condition];
Example: DELETE FROM javatpoint
WHERE Author="Sonoo";

4. SELECT: The SELECT statement is used to select data from a database. The data
returned is stored in a result table, called the result-set.
Syntax: SELECT column-name FROM table_name;
Example: SELECT emp_name FROM employee;

DATA CONTROL LANGUAGE (DCL):


1. Grant: It is used to give user access privileges to a database.
Example: GRANT [SELECT, UPDATE] ON table_name TO user_name;

2. Revoke: It is used to take back permissions from the user.


Example: REVOKE [SELECT, UPDATE] ON table_name FROM user_name;

3. Commit: Commit command is used to save all the transactions to the database.
Example: DELETE FROM CUSTOMERS
WHERE AGE = 25;
COMMIT;

4. Rollback: Rollback command is used to undo transactions that have not already been
saved to the database.
Example:
DELETE FROM CUSTOMERS
WHERE AGE = 25;
ROLLBACK;

5. Savepoint: It is used to roll back to the transaction back to a certain point without
rolling back the entire transaction.
Syntax: SAVEPOINT savepoint_name;

INTEGRITY CONSTRAINTS:
 Integrity Constraints in Database Management Systems are the set of pre-defined
rules responsible for maintaining the quality and consistency of data in the database.
 Evaluation against the rules mentioned in the integrity constraint is done every time
an insert, update, delete, or alter operation is performed on the table.

Integrity Constraints in DBMS are of 4 types:

1. Domain Constraint: There are 4 types of domain constraints:


1. Not Null
2. Unique
3. Check
4. Default

2. Entity Constraint:
Primary key: The entity integrity constraint states that primary key value can't be
null. This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those rows. A
table can contain a null value other than the primary key field.
Example: primary key (rollno);

3. Referential Constraint:
Foreign Key: A foreign key is the one that is used to link two tables together via the
primary key. It means the columns of one table points to the primary key attribute of
the other table.
Example: create table emp (eid number (3) primary key, ename varchar (30));
create table emp1 (eid number (3) references emp(eid), ename varchar (30));

4. Key Constraint:
Candidate Key: In a single table, more than one column as a primary key is called as
candidate key.
Example: primary key (sname, rollno);

OPERATORS:
1. Arithmetic Operators: Arithmetic operators can perform arithmetic operations on
numeric operands involved. Arithmetic operators are addition (+), subtraction (-),
multiplication (*) and division (/).
1. Addition (+): SELECT (4+3) FROM DUAL;
2. Subtraction (-): SELECT (4-3) FROM DUAL;
3. Multiplication (*): SELECT (4*3) FROM DUAL;
4. Division (/): SELECT (12/3) FROM DUAL;

2. Set Operators: SQL provides set operators to compare rows from two or more tables or to
combine the results obtained from two or more queries to obtain the final result. These
operators are used to join the results of two (or more) SELECT statements. These are:
There are different types of set operators that are mentioned below:
1. UNION: UNION eliminates the duplicate rows from the results.
Syntax: SELECT * FROM table1 UNION SELECT * FROM table2;
2. UNION ALL: UNION ALL prints all the values in the result.
Syntax: SELECT * FROM table1 UNION ALL SELECT * FROM table2;
3. MINUS: The MINUS operator allows you to filter out the results which are present in
the first table but absent in the second table.
Syntax: SELECT * FROM table1 MINUS SELECT * FROM table2;
4. INTERSECT: The INTERSECT operator allows you to find the results that exist in both
queries.
Syntax: SELECT * FROM table1 INTERSECT SELECT * FROM table2;

3. Pattern Matching Operator: LIKE clause is used to perform the pattern matching task in
SQL. LIKE clause searches for a match between the patterns in a query with the pattern in
the values present in an SQL table. LIKE clause can work with strings and numbers.
Syntax: SELECT * FROM table_name LIKE colum_name = condition;
Example: SELECT * FROM emp LIKE city = ‘P___’;

FUNCTIONS:
1. Aggregate Function: SQL aggregation function is used to perform the calculations on
multiple rows of a single column of a table. It returns a single value. It is also used to
summarize the data.
1. COUNT: Count function is used to Count the number of rows in a database table. It
can work on both numeric and non-numeric data types.
Syntax: SELECT COUNT (column_name) FROM table_name;
Example: SELECT COUNT (name) FROM emp;
2. SUM: Sum function is used to calculate the sum of all selected columns. It works on
numeric fields only.
Syntax: SELECT SUM (column_name) FROM table_name;
Example: SELECT SUM (salary) FROM emp;
3. AVG: The average function is used to calculate the average value of the numeric
type.
Syntax: SELECT AVG (column_name) FROM table_name;
Example: SELECT AVG (salary) FROM emp;
4. MAX: Maximum function is used to find the maximum value of a certain column.
Syntax: SELECT MAX (column_name) FROM table_name;
Example: SELECT MAX (salary) FROM emp;
5. MIN: Minimum function is used to find the minimum value of a certain column.
Syntax: SELECT MIN (column_name) FROM table_name;
Example: SELECT MIN (salary) FROM emp;

2. Arithmetic Functions: SQL arithmetic function is used to perform math calculations on


multiple rows of a single column of a table. It returns a single value. It is also used to
summarize the data.

1. ABS (): This SQL ABS () returns the absolute value of a number passed as an
argument.
2. CEIL (): This SQL CEIL () will round up any positive or negative decimal value within
the function upwards.
3. FLOOR (): The SQL FLOOR () will round up any positive or negative decimal value
down to the next least integer value.
4. MOD (): This SQL MOD () function returns the remainder from a division.
5. POWER (): This SQL POWER () function returns the value of a number raised to
another, where both of the numbers are passed as arguments.
6. SQRT (): The SQL SQRT () returns the square root of given value in the argument.

3. String Functions: String functions are used to perform an operation on input string and
return an output string. Following are the string functions defined in SQL:

1. LENGTH (): This function is used to find the length of a word.


Syntax: SELECT LENGTH (column_name) FROM table_name;
2. UPPER (): This function is used to change to uppercase.
Syntax: SELECT UPPER (column_name) FROM table_name;
3. LOWER (): This function is used to change to lowercase.
Syntax: SELECT LOWER (column_name) FROM table_name;
4. TRANSLATE (): This function is used to correct a spelling mistake in a word.
Syntax: SELECT TRANSLATE (‘value’, ‘from’, ‘to’) FROM table_name;
5. INITCAP (): This function is used to uppercase the first letter.
Syntax: SELECT INITCAP (column_name) FROM table_name;

4. Date and Time Functions: Date and time functions are used to perform an operation on
dates and times. Following are the date and time functions defined in SQL:

1. SYSDATE (): SELECT SYSDATE () FROM DUAL;


2. ADD_MONTHS (): SELECT ADD_MONTHS (SYSDATE, 5) FROM DUAL;
3. MONTHS_BETWEEN (): SELECT MONTHS_BETWEEN (SYSDATE, ‘10-12-2022’) FROM
DUAL;
4. NEXT_DAY (): SELECT NEXT_DAY (‘10-12-2022’, ‘MONDAY) FROM DUAL;
5. LAST_DAY (): SELECT LAST_DAY (SYSDATE, 5) FROM DUAL;

CLAUSES:
1. GROUP BY: SQL GROUP BY statement is used to arrange identical data into groups. The
GROUP BY statement is used with aggregation function.
Syntax: SELECT column FROM table_name
GROUP BY column;
Example:
SELECT company, count (*) FROM products
GROUP BY company;

2. HAVING: HAVING clause is used to specify a search condition for a group or an aggregate.
Having is used in a GROUP BY clause. If you are not using GROUP BY clause then you can use
HAVING function like a WHERE clause.
Syntax: SELECT column1, column2 FROM table_name
GROUP BY column1, column2 HAVING conditions;
Example: SELECT company, count (*) FROM products
GROUP BY company HAVING count (*)>2;

3. ORDER BY: The ORDER BY clause sorts the result-set in ascending or descending order. It
sorts the records in ascending order by default. DESC keyword is used to sort the records in
descending order.
Syntax: SELECT column1, column2 FROM table_name
ORDER BY column1, column2... [DESC];
Example: SELECT * FROM customer
ORDER BY name;

ER DIAGRAM:
 ER diagram stands for Entity-Relationship Diagram. It is a high-level data model. This
model is used to define the data elements and relationship for a specified system.
 It develops a conceptual design for the database. It also develops a very simple and
easy to design view of data.
 In ER modelling, the database structure is portrayed as a diagram called an entity-
relationship diagram.

Components of ER Diagram:
1. Entity: An entity may be any object, class, person or place. In the ER diagram, an entity
can be represented as rectangles.
1. Weak Entity: An entity that depends on another entity is called a weak entity. The
weak entity doesn't contain any key attribute of its own. The weak entity is
represented by a double rectangle.

2. Attribute: The attribute is used to describe the property of an entity. Ellipse is used to
represent an attribute.
1. Key Attribute: The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented by an ellipse with
the text underlined.
2. Composite Attribute: An attribute that composed of many other attributes is known
as a composite attribute. The composite attribute is represented by an ellipse, and
those ellipses are connected with an ellipse.
3. Multivalued Attribute: An attribute can have more than one value. These attributes
are known as a multivalued attribute. The double oval is used to represent
multivalued attribute.
4. Derived Attribute: An attribute that can be derived from another attribute is known
as a derived attribute. It can be represented by a dashed ellipse.

3. Relationship: Relationship is used to describe the relation between entities. Diamond or


rhombus is used to represent the relationship. Types of relationship are as follows:

1. One-to-One Relationship: When only one instance of an entity is associated with the
relationship, then it is known as one-to-one relationship.
2. One-to-many relationship: When only one instance of the entity on the left, and
more than one instance of an entity on the right associates with the relationship
then this is known as a one-to-many relationship.
3. Many-to-one relationship: When more than one instance of the entity on the left,
and only one instance of an entity on the right associates with the relationship then
it is known as a many-to-one relationship.
4. Many-to-many relationship: When more than one instance of the entity on the left,
and more than one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.

VIEW:
Views in SQL are considered as a virtual table. A view also contains rows and columns. To
create the view, we can select the fields from one or more tables present in the database. A
view can either have specific rows based on certain condition or all the rows of a table.

Syntax:
CREATE VIEW view_name AS
SELECT column1, column2...columnN FROM table_name
WHERE condition;
Example:
CREATE VIEW DetailsView AS
SELECT NAME, ADDRESS FROM Student_Details
WHERE STU_ID < 4;

SYNONYMS:

A synonym provides another name for database object, referred to as original object, that
may exist on a local or another server. A synonym belongs to schema, name of synonym
should be unique. A synonym cannot be original object for an additional synonym and
synonym cannot refer to user-defined function.

Syntax: CREATE SYNONYM synonym_name


FOR servername.databasename.schemaname.objectname;
Example:
CREATE SYNONYM Student
FOR Server1.MSBTE.Theem.Computer;

INDEX:
An index is a schema object. It is used by the server to speed up the retrieval of rows by
using a pointer. An index helps to speed up select queries and where clauses, but it slows
down data input, with the update and the insert statements. Indexes can be created or
dropped with no effect on the data.

Syntax: CREATE INDEX index_name ON table_name (column1, column2, …, columnN);


Example: CREATE INDEX studIndex ON student (firstName, lastName);

SEQUENCES:

A sequence is a user defined schema bound object that generates a sequence of numeric
values. Sequences are frequently used in many databases because many applications
require each row in a table to contain a unique value and sequences provide an easy way to
generate them. The sequence of numeric values is generated in an ascending or descending
order at defined intervals and can be configured to restart when exceeds the maximum
value.

Syntax: CREATE SEQUENCE sequence_name


START WITH initial_value
INCREMENT BY increment_value
MINVALUE minimum_value
MAXVALUE maximum_value
CYCLE|NOCYCLE;

JOINS:
1. INNER JOIN: Returns records that have matching values in both tables.
Syntax: SELECT column_name FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

2. LEFT OUTER JOIN: Returns all records from the left table, and the matched records
from the right table.
Syntax: SELECT column_name FROM table1
LEFT OUTER JOIN table2
ON table1.column_name = table2.column_name;

3. RIGHT OUTER JOIN: Returns all records from the right table, and the matched
records from the left table.
Syntax: SELECT column_name FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name = table2.column_name;

4. FULL JOIN: Returns all records in left and right table.


Syntax: SELECT column_name FROM table1
FULL JOIN table2
ON table1.column_name = table2.column_name;

NORMALIZATION:
Normalization is the process of organizing the data and the attributes of a database. It is
performed to reduce the data redundancy in a database and to ensure that data is stored
logically. Data redundancy means having the same data but at multiple places. It is
necessary to remove data redundancy because it causes anomalies in a database which
makes it very hard for a database administrator to maintain it. There are three types of
normal forms that are usually used in relational databases:

1. 1NF: A relation is in 1NF if every attribute is a single-valued attribute or it does not


contain any multi-valued or composite attribute, i.e., every attribute is an atomic
attribute. If there is a composite or multi-valued attribute, it violates the 1NF.
2. 2NF: The normalization of 1NF relations to 2NF involves the elimination of partial
dependencies. A partial dependency exists when any non-prime attributes, i.e., an
attribute not a part of the candidate key, is not fully functionally dependent on one
of the candidate keys. For a relational table to be in second normal form, it must
satisfy the following rules:
 The table must be in first normal form.
 It must not contain any partial dependency, i.e., all non-prime attributes are
fully functionally dependent on the primary key.
3. 3NF: The normalization of 2NF relations to 3NF involves the elimination of transitive
dependencies. For a relational table to be in third normal form, it must satisfy the
following rules:
 The table must be in the second normal form.
 No non-prime attribute is transitively dependent on the primary key.
 For each functional dependency X -> Z at least one of the following conditions
hold:
o X is a super key of the table.
o Z is a prime attribute of the table.

CURSORS:
Cursor is a Temporary Memory or Temporary Work Station. It is Allocated by Database
Server at the Time of Performing DML (Data Manipulation Language) operations on Table by
User. Cursors are used to store Database Tables. There are 2 types of Cursors: Implicit
Cursors, and Explicit Cursors. These are:

1. Implicit Cursors:
Implicit Cursors are also known as Default Cursors of Oracle. These Cursors are
allocated by Oracle when the user performs DML operations.

2. Explicit Cursors:
Explicit Cursors are Created by Users whenever the user requires them. Explicit
Cursors are used for Fetching data from Table in Row-By-Row Manner.

Syntax: DECLARE cursor_name CURSOR FOR SELECT column_name FROM table_name;


Example: DECLARE s1 CURSOR FOR SELECT * FROM studDetails;

Open Cursor: OPEN cursor_name;


Close cursor: CLOSE cursor_name;

FUNCTIONS:

Function in Oracle always accepts parameters, either single or multiple and returns a single
value. The functions are useful in the simplification of our code. Suppose we might have a
complex computation that appears in a number of queries. In such a case, we can build a
function that encapsulates the formula and uses it in each query.
Syntax: CREATE FUNCTION function_name (parameter_list)
RETURN datatype AS
BEGIN
//statements
RETURN value
END;

PROCEDURE:
A stored procedure in SQL is a group of SQL statements that are stored together in a
database. It allows you to pass the same statements multiple times, thereby, enabling
reusability.

Stored procedures provide some crucial benefits, which are:


 Reusable: Multiple users and applications can easily use and reuse stored procedures
by merely calling it.
 Easy to modify: You can quickly change the statements in a stored procedure as and
when you want to, with the help of the ALTER command.
 Security: Stored procedures allow you to enhance the security of an application or a
database by restricting the users from direct access to the table.
 Low network traffic: The server only passes the procedure name instead of the
whole query, reducing network traffic.
 Increases performance: Upon the first use, a plan for the stored procedure is created
and stored in the buffer pool for quick execution for the next time.

Syntax: CREATE or REPLACE PROCEDURE name(parameters) AS


variables;
BEGIN;
//statements;
END;

TRIGGER:
A trigger is a stored procedure in database which automatically invokes whenever a special
event in the database occurs. For example, a trigger can be invoked when a row is inserted
into a specified table or when certain table columns are being updated.

Syntax: CREATE OR REPLACE TRIGGER trigger_name


{BEFORE | AFTER}
[INSERT, DELETE, UPDATE, SELECT]
ON table_name
FOR each row
//trigger body
END;

DEFINITIONS:

Data: Data is recorded things like photo, audio, video etc. Mainly data is in three format int,
char, float.

Database: Database is the collection of interrelated data, for example student records,
employee records etc.

RDBMS: Collection of interrelated data and set of programs (software) that are stored and
used to access stored data.

Instances: Instances are the collection of information stored at a particular moment. The
instances can be changed by certain operations as like insertion, deletion of data. It may be
noted that any search query will not make any kind of changes in the instances.

Schema: Schema is the overall description of the database. The basic structure of how the
data will be stored in the database is called schema.
APPLICATION OF DBMS:

1. Railway Reservation System – In the rail route reservation framework, the


information base is needed to store the record or information of ticket
appointments, status about train’s appearance, and flight. Additionally, if trains get
late, individuals become acquainted with it through the information base update.
2. Library Management System – There are loads of books in the library so; it is difficult
to store the record of the relative multitude of books in a register or duplicate. Along
these lines, the data set administration framework (DBMS) is utilized to keep up all
the data identified with the name of the book, issue date, accessibility of the book,
and its writer.
3. Banking – Database the executive’s framework is utilized to store the exchange data
of the client in the information base.
4. Education Sector – Presently, assessments are led online by numerous schools and
colleges. They deal with all assessment information through the data set
administration framework (DBMS). In spite of that understudy’s enlistments
subtleties, grades, courses, expense, participation, results, and so forth all the data is
put away in the information base.
5. Credit card exchanges – The database Management framework is utilized for buying
on charge cards and age of month-to-month proclamations.
6. Social Media Sites – We all utilize online media sites to associate with companions
and to impart our perspectives to the world.
7. Broadcast communications –The Database executive’s framework is fundamental for
these organizations to store the call subtleties and month to month post-paid bills in
the information base.
8. Account – The information base administration framework is utilized for putting
away data about deals, holding and acquisition of monetary instruments, for
example, stocks and bonds in a data set.
9. Online Shopping – These days, web-based shopping has become a major pattern.
The items are sold and added uniquely with the assistance of the information base
administration framework (DBMS). Receipt charges, instalments, buy data these are
finished with the assistance of DBMS.
10. Manufacturing – Manufacturing organizations make various kinds of items and deal
them consistently. To keep the data about their items like bills, acquisition of the
item, amount, inventory network the executives, information base administration
framework (DBMS) is utilized.
11. Airline Reservation System –This framework additionally utilizes an information base
administration framework to store the records of flight take off, appearance, and
defer status.

CHARACTERISTICS OF DBMS:

 A database management system is able to store any kind of data in a database.


 The database management system has to support ACID (atomicity, consistency,
isolation, durability) properties.
 The Database management system allows so many users to access databases at the
same time.
 Backup and recovery are the two main methods which allow users to protect the
data from damage or loss.
 It also provides multiple views for different users in a single organization.
 It follows the concept of normalization which is helpful to minimize the redundancy
of a relation.
 It also provides users query language, helpful to insert, retrieve, update, and delete
the data in a database.

DATA INDEPENDENCE:

Data independence is the ability to modify the schema without affecting the programs and
the application to be rewritten. Data is separated from the programs, so that the changes
made to the data will not affect the program execution and the application.

The main purpose of the three levels of data abstraction is to achieve data independence. If
the database changes and expands over time, it is very important that the changes in one
level should not affect the data at other levels of the database. This would save time and
cost required when changing the database. There are two levels of data independence
based on three levels of abstraction. These are as follows:
 Physical Data Independence
 Logical Data Independence

DATA REDUNDANCY:

Redundancy in DBMS is having several copies of the same data in the database. Redundancy
may cause inconsistency in data when they are not properly updated. It may also cause an
increase in storage space and cost.
Redundancy in DBMS can be avoided by following the below approaches:
 Redundancy in DBMS can be avoided by normalizing the data through
database normalization.
 Proper database architecture design can avoid data redundancy.

DATABASE SECURITY:

Database Security means keeping sensitive information safe and to prevent the loss of data.
Security of data base is controlled by Database Administrator (DBA). The following are the
main control measures are used to provide security of data in databases:

1. Authentication
2. Access control
3. Inference control
4. Flow control
5. Applying Statistical Method
6. Encryption
DATA ABSTRACTION:

Data Abstraction is a process of hiding unwanted or irrelevant details from the end user. It
provides a different view and helps in achieving data independence which is used to
enhance the security of data.

The database systems consist of complicated data structures and relations. For users to
access the data easily, these complications are kept hidden, and only the relevant part of
the database is made accessible to the users through data abstraction.

Levels of abstraction for DBMS: In order to make the system efficient, developers use levels
of abstraction that hide irrelevant details from the users. Levels of abstraction simplify
database design. Mainly there are three levels of abstraction for DBMS, which are as
follows:
1. Physical or Internal Level
2. Logical or Conceptual Level
3. View or External Level

These levels are shown in the diagram below:


DBMS ARCHITECTURE:

DBMS architecture describes the structure and how the users are connected to a specific
database system. It also affects the performance of the database as it helps to design,
develop, implement, and maintain the database management system.

Database management systems are divided into multiple levels of abstraction for proper
functioning. These modules/layers describe the functioning and the design of the DBMS.
Since a database management system is not always directly accessible by the user or an
application, we can maintain it with the help of various architectures based on how the user
is connected to the database. These architectures follow a tier-based classification.

When the layers are increased in the architecture, the level of abstraction also increases,
resulting in an increase in the security and the complexity of the DBMS structure. All these
layers are independent, i.e., any modification performed in a particular layer does not affect
the other layer present in the architecture.

1. Single Tier Architecture (One-Tier Architecture): Single Tier DBMS Architecture is the
most straightforward DBMS architecture. All the DBMS components reside on a
single server or platform, i.e., the database is directly accessible by the end-user.
Because of this direct connection, the DBMS provides a rapid response, due to which
programmers widely use this architecture to enhance the local application.
In this structure, any modifications done by the client are reflected directly in the
database, and all the processing is done on a single server. Also, no network
connection is required to perform actions on the database. This database
management system is also known as the local database system.
Single Tier DBMS Architecture is used whenever:
 The data isn't changed frequently.
 No multiple users are accessing the database system.
 We need a direct and simple way to modify or access the database for
application development.
2. Two-Tier Architecture: The Two-Tier DBMS Architecture is used when we wish to
access the DBMS with the help of an application. Client-side applications can access
the database server directly with the help of API calls, making the application
independent of the database in terms of operation, design, and programming.
The main advantages of having a two-tier architecture over a single tier are:
 Multiple users can use it at the same time. Hence, it can be used in an
organization.
 It has high processing ability as the database functionality is handled by the
server alone.
 Faster access to the database due to the direct connection and improved
performance.
 Because of the two independent layers, it's easier to maintain.

3. Three-Tier Architecture: Three-Tier DBMS Architecture is the most widely used


DBMS architecture in which another layer known as Intermediate or Application
layer is added between the server (Database Layer) and the client (Presentation
Layer) systems to reduce the query processing load of the server. This application or
intermediate layer provides the end-user an abstract view of the database.
The main advantages of Three Tier DBMS Architecture are:
 Scalability - Since the database server isn't aware of any users beyond the
application layer and the application layer implements load balancing, there
can be as many clients as you want.
 Data Integrity - Data corruption and bad requests can be avoided because of
the checks performed in the application layer on each client request.
 Security - The removal of the direct connection between the client and server
systems via abstraction reduces unauthorized access to the database.
DATABASE USERS:

1. Application Programmers – They are the developers who interact with the database
by means of DML queries. These DML queries are written in the application
programs like C, C++, JAVA, Pascal, etc. These queries are converted into object code
to communicate with the database.
2. Sophisticated Users – They are database developers, who write SQL queries to
select/insert/delete/update data. They do not use any application or programs to
request the database.
3. Specialized Users – These are also sophisticated users, but they write special
database application programs. They are the developers who develop the complex
programs to the requirement.
4. Stand-alone Users – These users will have a stand-alone database for their personal
use. These kinds of the database will have readymade database packages which will
have menus and graphical interfaces.
5. Native Users – These are the users who use the existing application to interact with
the database to fulfil their requests.

DATABASE ADMINISTRATORS:

The administration and maintenance of the database are taken care of by the database
Administrator. The role of DBA is:

1. Installing and upgrading the DBMS Servers: DBA is responsible for installing a new
DBMS server for the new projects. He is also responsible for upgrading these servers
as there are new versions that come into the market or requirement.
2. Design and implementation: Designing the database and implementing is also DBA’s
responsibility. He should be able to decide on proper memory management, file
organizations, error handling, log maintenance, etc for the database.
3. Performance tuning: Since the database is huge and it will have lots of tables, data,
constraints, and indices, there will be variations in the performance from time to
time. It is the responsibility of the DBA to tune the database performance.
4. Migration: Sometimes, users using oracle would like to shift to SQL server or
Netezza. It is the responsibility of DBA to make sure that migration happens without
any failure, and there is no data loss.
5. Backup and Recovery: Proper backup and recovery programs needs to be developed
by DBA and has to be maintained by him. This is one of the main responsibilities of
DBA. Data/objects should be backed up regularly so that if there is any crash, it
should be recovered without much effort and data loss.
6. Security: DBA is responsible for creating various database users and roles, and giving
them different levels of access rights.
7. Documentation: DBA should be properly documenting all his activities so that if he
quits or any new DBA comes in, he should be able to understand the database
without any effort.

DATABASE STRUCTURE:

The database system is divided into three components: Query Processor, Storage Manager,
and Disk Storage. These are explained as following below.

1. Query Processor: It interprets the requests (queries) received from end user
via an application program into instructions.
2. Storage Manager: Storage Manager is a program that provides an interface
between the data stored in the database and the queries received. It is also
known as Database Control System.
3. Disk Storage: It contains the following components:
1. Data Files: It stores the data.
2. Data Dictionary: It contains the information about the structure of any
database object. It is the repository of information that governs the
metadata.
3. Indices: It provides faster retrieval of data item.
DATABASE BACKUP, RECOVERY AND
PRIVILEGES:

1. Backup: Backup refers to storing a copy of original data which can be used in case of
data loss. Backup is considered as one of the approaches to data protection.
Important data of the organization needs to be kept in backup efficiently for
protecting valuable data. Backup can be achieved by storing a copy of the original
data separately or in a database on storage devices. There are various types of
backups are available like full backup, incremental backup, Local backup, mirror
backup, etc. An example of a Backup can be SnapManager which makes a backup of
everything in the database.
2. Recovery: Recovery refers to restoring lost data by following some processes. When
a database fails due to any reason then there is a chance of data loss, so in that case
recovery process helps in improve the reliability of the database. An example of
Recover can be SnapManager which recovers the data from the last transaction.
There are two methods that are primarily used for database recovery. These are:
1. Log based recovery: In log-based recovery, logs of all database transactions
are stored in a secure area so that in case of a system failure, the database
can recover the data. All log information, such as the time of the transaction,
its data etc. should be stored before the transaction is executed.
2. Shadow paging: In shadow paging, after the transaction is completed its data
is automatically stored for safekeeping. So, if the system crashes in the
middle of a transaction, changes made by it will not be reflected in the
database.
3. Privilege: A privilege is permission to execute one particular type of SQL statement
or access a second persons’ object. Database privilege controls the use of computing
resources. Database privilege does not apply to the Database administrator of the
database.
DATABASE TRANSACTION:

A transaction is a logical unit of work that accesses and updates the contents of a database.
Read and write operations are used by transactions to access data. A transaction has several
states:

1. Active State: Every transaction starts out in the active state. The transaction is
currently being carried out in this state.
2. Partially Committed State: A transaction has reached this state when it completes all
operations but the data has not been saved to the database.
3. Failed State: The transaction is considered to be in the failed state if any of the
database recovery system’s checks fail.
4. Committed State: If a transaction completes its final operation successfully, it is
considered to be committed. In this state, all of the changes are written to memory
and as a result, saved on the database system permanently.
5. Aborted State: If any of the tests fail, the transaction is said to go to a failed state.
Upon entering this state, the database recovery system attempts to bring the
database to the previous consistent state (committed state). If this doesn’t happen
then the transaction would be rolled back or aborted so as to bring the database
back to a consistent state. Once it has been aborted, the database recovery module
will either kill the transaction or re-start the transaction.
6. Terminated State: If there is no rollback and the transaction is in the committed
state, the system is consistent and ready for a new transaction, while the old one is
terminated.

ACID Properties in DBMS are of extreme significance as they ensure accuracy, completeness,
and data integrity. Everyday occurrences such as using computer systems to buy things
would be difficult without these ACID properties, and the possibility for errors would be
enormous. ACID properties are followed before and after a transaction in order to preserve
database consistency.

1. Atomicity: The term atomicity is the ACID Property in DBMS that refers to the fact
that the data is kept atomic. It means that if any operation on the data is conducted,
it should either be executed completely, or it not at all. It also implies that the
operation should not be interrupted or just half completed. If any of the operations
aren’t completed fully, the transaction gets aborted. Atomicity is often referred to as
the ‘all or nothing’ rule.
2. Consistency: This ACID Property is used after each transaction; consistency is
checked to ensure nothing has gone wrong.
3. Isolation: Isolation is defined as a state of separation. Isolation is an ACID Property in
DBMS where no data from one database should impact the other and where many
transactions can take place at the same time. When two or more transactions occur
at the same time in the case of transactions, consistency should be maintained.
4. Durability: The ACID Property durability in DBMS refers to the fact that if an
operation is completed successfully, the database remains permanent in the disk.
The database’s durability should be such that even if the system fails or crashes, the
database will survive.

EF CODD’S RULES:

Rule 0 − Foundation rule: Any relational database management system that is propounded
to be RDBMS or advocated to be a RDBMS should be able to manage the stored data in its
entirety through its relational capabilities.

Rule 1 − Rule of Information: Relational Databases should store the data in the form of
relations. Tables are relations in Relational Database Management Systems. Be it any user
defined data or meta-data, it is important to store the value as an entity in the table cells.

Rule 2 − Rule of Guaranteed Access: The use of pointers to access data logically is strictly
forbidden. Every data entity which is atomic in nature should be accessed logically by using
a right combination of the name of table, primary key represented by a specific row value
and column name represented by attribute value.

Rule 3 − Rule of Systematic Null Value Support: Null values are completely supported in
relational databases. They should be uniformly considered as ‘missing information’. Null
values are independent of any data type. They should not be mistaken for blanks or zeroes
or empty strings. Null values can also be interpreted as ‘inapplicable data’ or ‘unknown
information.’

Rule 4 − Rule of Active and online relational Catalogue: The active online catalogue that
stores the metadata is called ‘Data dictionary’. The so-called data dictionary is accessible
only by authored users who have the required privileges and the query languages used for
accessing the database should be used for accessing the data of data dictionary.

Rule 5 − Rule of Comprehensive Data Sub-language: A single robust language should be able
to define integrity constraints, views, data manipulations, transactions and authorizations.

Rule 6 − Rule of Updating Views: Views should reflect the updates of their respective base
tables and vice versa. A view is a logical table which shows restricted data. Views generally
make the data readable but not modifiable. Views help in data abstraction.

Rule 7 − Rule of Set level insertion, update and deletion: A single operation should be
sufficient to retrieve, insert, update and delete the data.

Rule 8 − Rule of Physical Data Independence: Batch and end user operations are logically
separated from physical storage and respective access methods.

Rule 9 − Rule of Logical Data Independence: Batch and end users can change the database
schema without having to recreate it or recreate the applications built upon it.

Rule 10 − Rule of Integrity Independence: Integrity constraints should be available and


stored as metadata in data dictionary and not in the application programs.

Rule 11 − Rule of Distribution Independence: The Data Manipulation Language of the


relational system should not be concerned about the physical data storage and no
alterations should be required if the physical data is centralized or distributed.

Rule 12 − Rule of Non-Subversion: Any row should obey the security and integrity
constraints imposed. No special privileges are applicable.
BLOCK STRUCTURE OF PL/SQL:

DATATYPES IN PL/SQL:
EXCEPTION HANDLING:

An exception is an error which disrupts the normal flow of program instructions. PL/SQL
provides us the exception block which raises the exception thus helping the programmer to
find out the fault and resolve it.
Syntax: DECLARE
declarations section;
BEGIN
executable command(s);
EXCEPTION
WHEN exception1 THEN
statement1;
WHEN exception2 THEN
statement2;
[WHEN others THEN]
/* default exception handling code */
END;

COMPARISONS:

Difference between Procedure and Functions

Difference between DBMS and File processing

Difference between Primary key and foreign key

Difference between Truncate and delete command

Difference between Primary and unique key

Difference between Hierarchal and network model

Difference between Hierarchal and relational model

You might also like