0% found this document useful (0 votes)
5 views4 pages

Comprehensive Guide to DBMS Concepts

Uploaded by

defaxo2237
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Comprehensive Guide to DBMS Concepts

Uploaded by

defaxo2237
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Database Management System (DBMS) – Detailed Study

Notes
Jayawantrao Sawant Polytechnic, Department of Computer Engineering

Academic Year 2025–26

Question No. 1 – Attempt any FIVE


Refer to previous notes for Q1 answers (basic definitions, syntax, and examples).
Question No. 2 – Attempt any FIVE (Detailed Explanations)
a) Explain any four DML commands with syntax and example

DML stands for Data Manipulation Language. These commands modify data stored in tables.

1. INSERT: Adds new records.


Syntax: INSERT INTO table_name (col1, col2) VALUES (val1, val2);
Example: INSERT INTO Employee VALUES(101, 'Amit', 30000);

2. UPDATE: Changes existing records.


Syntax: UPDATE table_name SET column=value WHERE condition;
Example: UPDATE Employee SET Salary=35000 WHERE Emp_ID=101;

3. DELETE: Removes records.


Syntax: DELETE FROM table_name WHERE condition;
Example: DELETE FROM Employee WHERE Emp_ID=101;

4. SELECT: Retrieves records.


Syntax: SELECT col1, col2 FROM table_name WHERE condition;
Example: SELECT * FROM Employee WHERE Salary>25000;

Note: DML commands affect table data but not structure.

b) Explain aggregate function with example

Aggregate functions perform calculations on multiple rows and return one result.

1. SUM(): Adds numeric values.


Example: SELECT SUM(Salary) FROM Employee;

2. AVG(): Finds average value.


Example: SELECT AVG(Salary) FROM Employee;

3. COUNT(): Counts number of rows.


Example: SELECT COUNT(*) FROM Employee;

4. MAX()/MIN(): Returns largest/smallest value.


Example: SELECT MAX(Salary), MIN(Salary) FROM Employee;

These are used with GROUP BY for grouped summaries.

c) Write PL/SQL program to identify largest of three numbers

Program to find largest of three numbers using IF-ELSE conditions:

DECLARE
a NUMBER := &a;
b NUMBER := &b;
c NUMBER := &c;
largest NUMBER;
BEGIN
IF a>b AND a>c THEN largest:=a;
ELSIF b>c THEN largest:=b;
ELSE largest:=c;
END IF;
DBMS_OUTPUT.PUT_LINE('Largest number is: '||largest);
END;

Demonstrates decision control and DBMS output handling.

d) Explain function in PL/SQL with suitable example

Functions are named PL/SQL blocks that return a value and can be reused.

Syntax:
CREATE OR REPLACE FUNCTION func_name(parameter datatype) RETURN datatype IS
BEGIN
RETURN value;
END;

Example:
CREATE OR REPLACE FUNCTION get_bonus(salary NUMBER) RETURN NUMBER IS BEGIN
RETURN salary*0.10; END;
Usage:
SELECT get_bonus(50000) FROM dual;

Advantages: Reusability, modularity, easy maintenance, improved performance.

e) What is database backup? Explain types and causes of failure

A backup is a copy of data used for restoration after data loss.

Types of Failure:
Transaction Failure, System Crash, Media Failure, Application Failure.

Causes: Power loss, hardware failure, software bug, human error.

Backup Types:
1. Full Backup – Complete copy of DB.
2. Incremental – Only changed data.
3. Differential – Data changed since last full backup.

f) Describe ACID properties of transaction

Transactions ensure reliability using ACID properties:


1. Atomicity – All-or-nothing execution.
2. Consistency – Preserves integrity.
3. Isolation – Independent execution.
4. Durability – Changes remain permanent.
Example: In a fund transfer, debit and credit must both succeed or rollback.

g) Explain set operators with example

Set operators combine results of multiple queries.

UNION – Combines unique results.


UNION ALL – Combines all (including duplicates).
INTERSECT – Returns common records.
MINUS – Returns records in first query but not second.

Example:
SELECT City FROM Customers UNION SELECT City FROM Suppliers;

h) Create a view and sequence for Customer table

Schema: Customer(Cust_id, Cust_name, Cust_addr, Cust_city)

View creation:
CREATE VIEW Pune_Cust AS SELECT Cust_id, Cust_name FROM Customer WHERE
Cust_city='Pune';

Sequence creation:
CREATE SEQUENCE Cust_seq START WITH 1 INCREMENT BY 1;

The sequence auto-generates IDs for new customers.

i) Explain any two DDL commands with example

DDL defines and manages database structure.

CREATE – Creates table or object.


Example: CREATE TABLE Student(id NUMBER, name VARCHAR2(20));

ALTER – Modifies existing table.


Example: ALTER TABLE Student ADD age NUMBER;

DROP – Deletes object permanently.


Example: DROP TABLE Student;

Common questions

Powered by AI

DDL commands define and manage the structure of a database, whereas DML commands manipulate the data within those structures. DDL commands include CREATE, ALTER, and DROP, which create, modify, and delete the structures of database objects, respectively. For example, CREATE TABLE Student(id NUMBER, name VARCHAR2(20)) establishes a new table structure . Conversely, DML commands like INSERT, UPDATE, and DELETE are used to add, modify, or remove data within existing tables. INSERT INTO Employee VALUES(101, 'Amit', 30000) is an instance of DML operation that inserts a record into a table . Thus, DDL deals with schema manipulation, while DML involves data manipulation within those schemas.

Backup strategies are essential for safeguarding database data against various types of failure such as transaction failure, system crash, media failure, and application failure. Backup types include: 1) Full Backup, which creates a complete copy of the entire database, securing all data at a specific point in time . 2) Incremental Backup, which only saves data that has changed since the last backup, optimizing storage space and time . 3) Differential Backup, which backs up data changed since the last full backup, balancing full and incremental processes . These backups protect against data loss due to unexpected failures like power loss, hardware malfunction, software bugs, or human errors, ensuring data availability and continuity .

Aggregate functions in SQL perform calculations on multiple rows of a single column and return a single value. These functions include SUM, AVG, COUNT, and MAX/MIN . For example, SUM(Salary) calculates the total of all salary values in the Employee table . They are often used with the GROUP BY clause to provide summary data; for example, grouping employees by department to calculate the total salary per department. This enhances data analysis by allowing the aggregation of data into meaningful summaries .

Set operators in SQL are used to combine results from multiple queries into a single result set. UNION merges the results of two queries, returning unique records from both . UNION ALL also combines results but includes all duplicates, beneficial for complete dataset combination rather than deduplicated results . INTERSECT returns only those records that appear in both queries, useful for finding common items across datasets . MINUS yields records present in the first query but not in the second, effective for identifying differences between datasets . These operators facilitate complex data retrieval and are applied depending on whether you need to unite, exclude, or find commonalities between datasets.

Sequences in SQL are important for generating unique numeric identifiers, often used for primary keys. They operate independently of table data, increasing values with each use based on specified increments. For example, CREATE SEQUENCE Cust_seq START WITH 1 INCREMENT BY 1 initializes a sequence starting at 1, incrementing by 1 for each subsequent value . Sequences ensure that identifiers are unique and efficiently manage surrogate keys across tables without requiring complex logic in the application code . They are particularly effective in multi-user environments or when generating values for parallel insertions.

Creating a view in SQL involves defining a virtual table based on the result set of a query. The syntax is CREATE VIEW view_name AS SELECT column1, column2 FROM table WHERE condition. For example, CREATE VIEW Pune_Cust AS SELECT Cust_id, Cust_name FROM Customer WHERE Cust_city='Pune' creates a view for customer data in Pune . Views simplify complex queries by abstracting commonly used query patterns, enhance security by providing restricted data access, and support logical data segmentation, easing maintenance and enhancing consistency across user queries .

PL/SQL functions enhance database performance and maintainability by encapsulating reusable chunks of code that can be invoked as needed. This approach supports modularity, reduces code duplication, and improves efficiency by streamlining repetitive calculations. An example is the function get_bonus, which calculates a 10% bonus based on a given salary: CREATE OR REPLACE FUNCTION get_bonus(salary NUMBER) RETURN NUMBER IS BEGIN RETURN salary*0.10; END . This function can be reused across different parts of an application, minimizing errors and saving development time, ultimately improving performance and maintainability through concise code organization .

The ACID properties in database transactions ensure reliability and data integrity. They include: 1) Atomicity, which ensures that all parts of a transaction are completed successfully or none at all, maintaining an all-or-nothing execution . 2) Consistency, which guarantees that a transaction brings the database from one valid state to another, preserving database integrity . 3) Isolation, which ensures that transactions are executed independently, preventing them from affecting each other . 4) Durability, which ensures that once a transaction is committed, its changes are permanent, even in the event of a system failure . These properties collectively maintain the stability and correctness of the database system, even under concurrent operations.

A PL/SQL program can identify the largest of three numbers using conditional IF-ELSE logic. Consider the following program: DECLARE a NUMBER := &a; b NUMBER := &b; c NUMBER := &c; largest NUMBER; BEGIN IF a>b AND a>c THEN largest:=a; ELSIF b>c THEN largest:=b; ELSE largest:=c; END IF; DBMS_OUTPUT.PUT_LINE('Largest number is: '||largest); END . This program evaluates each condition sequentially to determine the largest number. This kind of logic is beneficial in database applications for tasks requiring comparison-based evaluations, such as ranking items, conditional data processing, or making decisions based on SQL query results .

DML commands in SQL are used to modify the data stored in database tables without altering the structure of the database itself. Examples of DML commands include: 1) INSERT, which adds new records to a table, with syntax like INSERT INTO Employee VALUES(101, 'Amit', 30000). 2) UPDATE, which changes existing records, for example, UPDATE Employee SET Salary=35000 WHERE Emp_ID=101 . 3) DELETE, which removes records from a table, such as DELETE FROM Employee WHERE Emp_ID=101 . 4) SELECT, which retrieves data, for instance, SELECT * FROM Employee WHERE Salary>25000 . Each of these commands enables specific operations on the data to facilitate various requirements for data manipulation.

You might also like