RDBMS Q& A
RDBMS Q& A
==WITHOUT
HUSTLE,TALENT WILL ONLY YOU CARRY SO
FAR==
=HOPE THIS
EFFORTS HELPS A LOT=
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-----------------------------------
RDBMS:
1)Manages and organizes data in a database using the
relational data model.
2)Enforces a predefined structure using tables, rows, and
columns.
3)Stores data in a tabular format where each row represents
a unique record and each column represents a data attribute.
4)Provides mechanisms for ensuring data integrity and
enforcing relationships between data through primary keys,
foreign keys, and constraints.
5)Supports ACID transactions to ensure data consistency
and reliability.
6)Utilizes SQL (Structured Query Language) for querying
and manipulating data.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
---------------------------------
Q.2)explain any four objects of ORACLE?
Disadvantages of RDBMS:
1)Complexity in design and management.
2)Performance overhead due to relationships and
constraints.
3)Limited flexibility for unstructured or rapidly changing
data.
4)Cost of commercial RDBMS products.
5)Challenges in horizontal scalability.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-----------------------------
Q.7)what is TRIGGER? list types of TRIGGERS?
Triggers are predefined actions in RDBMS that execute
automatically in response to specified events or changes.
Types of Triggers:
1)DML Triggers (Data Manipulation Language Triggers):
1)NO_DATA_FOUND:
1)Scalar Datatypes:
NUMBER: Represents numeric values.
VARCHAR2/CHAR: Used for storing strings of characters.
DATE: Represents date and time values.
BOOLEAN: Represents true or false values.
BINARY_INTEGER: Used for integer values.
PLS_INTEGER: Similar to BINARY_INTEGER, but with
stricter range checks.
BOOLEAN: Represents true, false, or null values.
RAW: Stores binary data as a sequence of bytes.
2)Composite Datatypes:
RECORD: A composite datatype that holds related fields
under a single variable.
TABLE: Represents a collection of homogeneous data
elements.
3)Reference Datatypes:
REF CURSOR: A cursor variable that holds the address of a
query result.
REF: Represents a reference to an object in the database.
4)LOB Datatypes:
CLOB: Stores large character data.
BLOB: Stores large binary data.
NCLOB: Stores large Unicode character data.
BFILE: Stores a reference to a binary file stored outside the
database.
5)User-Defined Datatypes:
OBJECT: Represents a user-defined object type.
VARRAY: Represents a variable-size array.
TABLE: Represents a nested table type.
RECORD: User-defined record type.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-------------
Q.11)what is block?list its types?
A PL/SQL block is a group of related statements that
organize code and control its execution.
It consists of declaration, execution, and exception handling
sections.
1)Anonymous Block: Nameless block of code for one-time
execution.
2)Stored Procedure: Named block of code stored in the
database for reuse.
3)Function: Named block of code that returns a value.
4)Package: Container for related procedures, functions, and
variables.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
------------
Q.12)what is cursor?explain various attributes of cursor
with example?
A cursor in PL/SQL is a mechanism that allows you to
retrieve and manipulate query results row by row.
It provides a way to traverse through the records returned
by a SELECT statement and perform operations on them.
Attributes of a cursor in PL/SQL:
1)%FOUND:
DECLARE
CURSOR c_emp IS SELECT * FROM employees;
v_emp c_emp%ROWTYPE;
BEGIN
OPEN c_emp;
LOOP
FETCH c_emp INTO v_emp;
EXIT WHEN c_emp%NOTFOUND;
-- Process the current row
END LOOP;
CLOSE c_emp;
END;
2)%NOTFOUND:
3)%ROWCOUNT:
DECLARE
CURSOR c_emp IS SELECT * FROM employees
WHERE salary > 5000;
v_emp c_emp%ROWTYPE;
BEGIN
OPEN c_emp;
FETCH c_emp INTO v_emp;
IF c_emp%ROWCOUNT > 0 THEN
-- Process the fetched row
ELSE
-- No rows matched the condition
END IF;
CLOSE c_emp;
END;
-------------------------------------------------------------------------
-------------------------------------------------------------------------
--------
Q.13)what is exception handling?explain user defined
exceptions with examples?
Exception handling is a mechanism in PL/SQL that allows
you to handle and manage errors or exceptional
conditions that may occur during the execution of a
program.
User-defined exceptions:
EXAMPLE:
DECLARE
my_exception EXCEPTION;
PRAGMA EXCEPTION_INIT(my_exception, -20001);
balance NUMBER := 1000;
withdrawal_amount NUMBER := 2000;
BEGIN
IF withdrawal_amount > balance THEN
RAISE my_exception;
ELSE
balance := balance - withdrawal_amount;
DBMS_OUTPUT.PUT_LINE('Withdrawal successful.
Remaining balance: ' || balance);
END IF;
EXCEPTION
WHEN my_exception THEN
DBMS_OUTPUT.PUT_LINE('Insufficient balance.
Cannot perform withdrawal.');
END;
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-------------------
Q.14)what is PL/SQL?list the sections of PL/SQL block?
PL/SQL (Procedural Language/Structured Query Language)
is a procedural extension of SQL used in Oracle Database.
It allows the creation of stored procedures, functions,
triggers, and packages, enhancing the capabilities of SQL
for data manipulation and programmatic logic.
Declaration section:
#SYNTAX:
[EXCEPTION
-- Exception handling section (optional)
exception handling statements]
END [procedure_name];
-------------------------------------------------------------------------
-------------------------------------------------------------------------
----------
Q.16)write a note on package in PL/SQL?
package is a schema object that contains definitions for a
group of related functionalities.
A package includes variables, constants, cursors,
exceptions, procedures, functions, and subprograms.
A package in PL/SQL is a schema object that groups related
procedures, functions, variables, and other constructs
together.
It consists of a specification (public interface) and a body
(implementation). Packages organize code, promote
reusability,
encapsulate functionality, and allow for public and private
components. They improve code organization,
maintainability,
and performance while providing a way to persist state and
manage dependencies.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
------------------------------
Q.16)what is CURSOR? explain different types of
CURSORS?
execution:
DECLARE
total_price NUMBER := 1500;
BEGIN
DBMS_OUTPUT.PUT_LINE('Discount amount: ' ||
calculate_discount(total_price));
END;
/
-------------------------------------------------------------------------
-------------------------------------------------------------------------
------------------
Q.18)write syntax for TRIGGER?
DECLARE
emp_record employees%ROWTYPE;
BEGIN
SELECT * INTO emp_record FROM employees WHERE
employee_id = 100;
-- Access individual columns using
emp_record.column_name
-- Rest of the logic
END;
-------------------------------------------------------------------------
-------------------------------------------------------------------------
---------------------------
Q.20)list RDBMS packages.explain any one in detail?
Oracle Database:
1)DBMS_OUTPUT
2)DBMS_SCHEDULER
3)DBMS_SQL
4)UTL_FILE
5)DBMS_METADATA
6)DBMS_LOB
BEGIN
DBMS_OUTPUT.PUT_LINE('Hello, world!');
END;
/
-------------------------------------------------------------------------
-------------------------------------------------------------------------
----------------
Q.21) what is transaction?list properties of transaction?
transaction refers to a logical unit of work that consists of
one or more database operations.
Transactions help maintain the consistency, integrity, and
reliability of data in a database.
Properties of a transaction are commonly referred to as the
ACID properties, which stand for:
T1:
Schedule 1: T1, T2
Transaction T2:
Schedule 1: T1 followed by T2
Schedule 2: T2 followed by T1
T2: Read Account B's balance.
T2: Write Account B's balance.
T1: Read Account A's balance.
T1: Write Account A's balance.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
Q.26)what is schedule?list types of schedule?
A schedule in database management systems represents the
order of executing transactions and their operations.
Types of schedules include:
#EXAMPLE:
Example of Two-Phase Locking (2PL) protocol:
iv)SYSTEM ERROR:Unexpected
condition disrupting program execution.
vi)DOWNGRADING:Reverting to an older
version of a system or component due to
incompatibility or preference for a previous
version.
viii)TIMESTAMP:Unique time-based
identifier used for ordering and coordination of events or
transactions.
-------------------------------------------------------------------------
-------------------------------------------------------------------------
-----------------------------------
Q.38)what is log?explain log based recovery?
Log: In the context of databases, a log is a sequential record
of all operations or changes made to a database.
It serves as a reliable and persistent record of transactions
and their associated actions, including updates, inserts,
and deletes, allowing for recovery and rollback in case of
failures or errors.