DBMS Full
DBMS Full
Code:
sql
,
SELECT * FROM table_name;
○
○ Explanation: DML queries are used to manipulate data within database
tables. SELECT retrieves data, INSERT adds new records, UPDATE
modifies existing data, and DELETE removes records.
2. List DCL (Data Control Language) queries
○ Syntax: GRANT, REVOKE
Code:
sql
,
GRANT SELECT, INSERT ON table_name TO user;
○
○ Explanation: DCL commands manage permissions in SQL. GRANT
provides specific rights to users, and REVOKE withdraws previously
granted permissions.
3. Explain Clauses in SQL with examples
○ Syntax: WHERE, ORDER BY, GROUP BY, HAVING
Code:
sql
,
SELECT column_name FROM table_name WHERE condition;
○
○ Explanation: Clauses in SQL are used to filter (WHERE), sort (ORDER BY),
group (GROUP BY), and restrict grouped results (HAVING).
4. Explain JOIN in SQL with examples
○ Syntax: INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN
Code:
sql
,
SELECT a.column1, b.column2 FROM table1 a INNER JOIN table2 b ON
a.id = b.id;
○
○ Explanation: JOINS are used to combine records from multiple tables.
INNER JOIN returns matching records; LEFT JOIN returns all records
from the left table and matching ones from the right; RIGHT JOIN does
the opposite, and FULL OUTER JOIN combines all.
5. Explain the use of nested subqueries with examples
Syntax:
sql
,
SELECT column_name FROM table_name WHERE column_name = (SELECT
column_name FROM table_name WHERE condition);
○
○ Explanation: Nested subqueries allow one query to be embedded within
another. This approach is useful for filtering data based on the result of
another query.
6. Explain Relational operators with examples
○ Operators: =, <>, >, <, >=, <=
Code:
sql
,
SELECT * FROM table_name WHERE column_name > value;
○
○ Explanation: Relational operators compare values. For example, =
checks for equality, <> for inequality, and > for greater-than
relationships.
7. Explain Arithmetic operators with examples
○ Operators: +, -, *, /
Code:
sql
,
SELECT salary + bonus AS total_salary FROM employees;
○
○ Explanation: Arithmetic operators perform mathematical calculations.
They can be used to calculate sums, differences, products, and
quotients in SQL queries.
8. Explain Logical operators with examples
○ Operators: AND, OR, NOT
Code:
sql
,
SELECT * FROM employees WHERE department = 'Sales' AND salary >
50000;
○
○ Explanation: Logical operators combine multiple conditions. AND
requires all conditions to be true, OR requires any one, and NOT negates
the condition.
9. Explain Set operators with examples
○ Operators: UNION, INTERSECT, EXCEPT
Code:
sql
,
SELECT column_name FROM table1 UNION SELECT column_name FROM table2;
○
○ Explanation: Set operators merge the results of two queries. UNION
combines unique records, INTERSECT returns common records, and
EXCEPT shows records in the first query but not in the second.
10. Explain Numeric functions with examples
○ Examples: ABS, POWER, SQRT
Code:
sql
,
SELECT ABS(-10) AS AbsoluteValue, POWER(2, 3) AS PowerValue;
○
○ Explanation: Numeric functions perform calculations on numeric
values. ABS returns the absolute value, POWER raises a number to a
power, and SQRT computes square roots.
11. Explain Date functions with examples
○ Examples: CURRENT_DATE, DATEADD, DATEDIFF
Code:
sql
,
SELECT CURRENT_DATE, DATEADD(day, 5, CURRENT_DATE) AS NewDate;
○
○ Explanation: Date functions manipulate date values, e.g.,
CURRENT_DATE provides today’s date, DATEADD adds days, and
DATEDIFF finds the difference between two dates.
12. Explain String functions with examples
○ Examples: UPPER, LOWER, CONCAT
Code:
sql
,
SELECT UPPER('hello') AS Uppercase, CONCAT('Hello', 'World') AS
CombinedText;
○
○ Explanation: String functions modify text values, such as converting to
uppercase (UPPER) or combining strings (CONCAT).
13. Explain Aggregate functions with examples
○ Examples: SUM, COUNT, AVG, MIN, MAX
Code:
sql
,
SELECT SUM(salary) AS TotalSalary, COUNT(*) AS TotalEmployees FROM
employees;
○
○ Explanation: Aggregate functions summarize data across multiple
records. SUM calculates the total, COUNT finds the record count, and AVG
computes averages.
14. Explain Views with examples
Syntax:
sql
,
CREATE VIEW view_name AS SELECT column1, column2 FROM table_name
WHERE condition;
○
○ Explanation: A view is a virtual table based on a SELECT query. It can
simplify complex queries and provide a layer of security by restricting
direct access to tables.
15. Explain Sequences with examples
Syntax:
sql
,
CREATE SEQUENCE seq_name START WITH 1 INCREMENT BY 1;
○
○ Explanation: Sequences generate unique numeric values, often used for
auto-incrementing primary keys in tables.
16. Explain Indexes with examples
Syntax:
sql
,
CREATE INDEX index_name ON table_name (column_name);
○
○ Explanation: An index improves the speed of data retrieval on a
specified column. It acts like a lookup table to help the database locate
records faster.
Syntax:
plsql
,
DECLARE
-- Variable declarations
BEGIN
-- Executable statements
EXCEPTION
-- Exception handling
END;
●
● Explanation: A PL/SQL block contains three sections: the Declaration section
(optional), Execution section (mandatory), and Exception Handling section (optional).
This structure organizes code for logical flow and error handling.
19. Explain IF, IF-ELSE, and ELSIF with examples
Syntax:
plsql
,
IF condition THEN
-- Statements
ELSIF condition THEN
-- Statements
ELSE
-- Statements
END IF;
●
● Explanation: Conditional statements in PL/SQL allow branching logic. IF checks a
condition, ELSE executes code when IF is false, and ELSIF provides multiple
conditions.
20. Explain different loops in PL/SQL with examples
● Syntax: LOOP, WHILE, FOR
Code:
plsql
,
FOR i IN 1..5 LOOP
DBMS_OUTPUT.PUT_LINE(i);
END LOOP;
●
● Explanation: Loops execute a block of statements repeatedly. FOR loop iterates a
fixed number of times, WHILE loop continues while a condition is true, and
LOOP...EXIT can be used with custom exit conditions.
21. Explain the use of GOTO with examples
Syntax:
plsql
,
<<label>>
BEGIN
-- Code
GOTO label;
END;
● Explanation: GOTO transfers control to a labeled statement. While it can help in error
handling, it’s generally avoided as it may reduce code readability.
22. What do you mean by Exception? Explain with examples
Syntax:
plsql
,
BEGIN
-- Statements
EXCEPTION
WHEN NO_DATA_FOUND THEN
-- Handle exception
END;
●
● Explanation: Exceptions are runtime errors. PL/SQL allows error handling with
EXCEPTION blocks, making code robust by managing anticipated errors like
NO_DATA_FOUND or ZERO_DIVIDE.
23. What is a Cursor? Explain with examples
Syntax:
plsql
,
DECLARE
CURSOR cursor_name IS SELECT column FROM table;
●
● Explanation: A cursor allows row-by-row processing of SQL query results. Explicit
cursors offer control over fetching and handling large datasets in loops.
24. What is a Procedure? Explain with examples
Syntax:
plsql
,
CREATE PROCEDURE procedure_name AS
BEGIN
-- Statements
END;
●
● Explanation: A procedure is a stored subroutine in PL/SQL. It can perform a specific
task and may include parameters to handle different inputs.
25. What is a Function? Explain with examples
Syntax:
plsql
,
CREATE FUNCTION function_name RETURN return_datatype AS
BEGIN
-- Statements
END;
●
● Explanation: A function is similar to a procedure but must return a single value.
Functions are useful for calculations and can be called within SQL queries.
Syntax:
plsql
,
CREATE TRIGGER trigger_name
BEFORE INSERT ON table_name
FOR EACH ROW
BEGIN
-- Trigger code
END;
●
● Explanation: Triggers automatically execute specified actions in response to table
events (e.g., INSERT, UPDATE, DELETE), often used for enforcing business rules.
27. Explain types of users. Also write functions of DBA (Database Administrator)
● Explanation: Users can be categorized as end users, application developers, and
administrators. DBAs manage database security, backup, tuning, and storage,
ensuring data integrity and performance.
28. Explain ACID properties
● Explanation: ACID stands for Atomicity, Consistency, Isolation, and Durability. These
properties ensure reliable database transactions, where operations are either fully
completed or rolled back, maintaining data integrity.
29. Explain states of a transaction
● Explanation: Transaction states include Active (executing), Partially
Committed, Committed, Failed, and Aborted. This lifecycle ensures all or none
of the transaction’s changes are applied.
30. What is failure? Explain its types
● Explanation: Database failures include transaction, system, and media failures.
Transaction failures are due to logical errors, system failures relate to power outages,
and media failures involve hardware malfunctions.
31. Explain DB backup
● Explanation: Database backup creates a copy of data, protecting against data loss.
Regular backups can be full, incremental, or differential, allowing recovery from
corruption or loss.
32. Explain data recovery
● Explanation: Data recovery uses backups and transaction logs to restore lost or
corrupted data. Recovery processes include roll-forward (applying logs) and
roll-backward (undoing transactions) for restoring consistency.
33. Explain the following:
● Data Warehouse: A centralized data repository for analysis, consolidating data from
various sources to support decision-making.
● Data Mining: The process of analyzing large datasets to find patterns, trends, and
insights for decision support.
● Data Lakes: A storage repository holding vast raw data in its native format until it’s
needed.
● Big Data: Large, complex data sets from diverse sources that require advanced
methods for storage, processing, and analysis.
● MongoDB and DynamoDB: MongoDB is a NoSQL, document-oriented database,
while DynamoDB is Amazon’s managed NoSQL database for scalable,
high-performance applications.