DBMS Questions Answers
DBMS Questions Answers
Types of Databases:
● Relational Databases (RDBMS): Organize data into tables with rows and columns
(e.g., MySQL, PostgreSQL).
● NoSQL Databases: Store data in formats other than tables, such as key-value pairs,
documents, or graphs (e.g., MongoDB, Cassandra).
● Object-Oriented Databases: Store data as objects, similar to object-oriented
programming (e.g., ObjectDB).
● Distributed Databases: Data is stored across multiple physical locations (e.g., Google
Spanner).
e
● In-Memory Databases: Store data in the main memory rather than on disk for faster
access (e.g., Redis).
● Graph Databases: Focus on the relationships between data, using nodes, edges, and
sd
properties (e.g., Neo4j).
i_
● DBMS (Database Management System): A software that manages databases, allowing
storage, retrieval, and updating of data (e.g., Microsoft Access).
● RDBMS (Relational Database Management System): A type of DBMS that uses a
sh
relational model to store data in tables with rows and columns, supporting ACID
properties (e.g., MySQL, Oracle).
Q3. Normalization:
an
● Concept: The process of organizing data to reduce redundancy and improve data
integrity.
● Types:
○ 1NF (First Normal Form): Ensures that each column contains atomic
m
● A unique identifier for each record in a table. It is important because it ensures that each
record can be uniquely identified, which is essential for maintaining data integrity and
establishing relationships between tables.
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
Name VARCHAR(100)
);
e
● A field (or collection of fields) in one table that uniquely identifies a row of another table,
sd
establishing a link between the two tables. It ensures referential integrity by enforcing a
relationship between the foreign key and the primary key of the referenced table.
i_
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
sh
CustomerID INT,
FOREIGN KEY (CustomerID) REFERENCES Customers(CustomerID)
);
an
● DELETE: Removes rows from a table based on a condition. It can be rolled back
(transactional).
● TRUNCATE: Removes all rows from a table, but the table structure remains. It cannot
hi
e
sd
SELECT Orders.OrderID, Customers.CustomerName
FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
i_
-- INNER JOIN
● Clustered Index: Sorts and stores the data rows of the table based on the indexed
column(s). There can be only one clustered index per table because it defines the
physical order of data.
@
● Non-Clustered Index: Contains a sorted list of references to the table data without
altering the physical order of the rows. A table can have multiple non-clustered indexes.
● A precompiled collection of SQL statements stored in the database that can be executed
as a unit. It is used to encapsulate complex business logic, improve performance, and
enhance security.
e
Q12. Triggers:
sd
● Special stored procedures that automatically execute in response to certain events on a
table or view, such as INSERT, UPDATE, or DELETE. They are used to enforce business
rules, maintain audit trails, and replicate data.
i_
CREATE TRIGGER trgAfterInsert ON Employees
sh
AFTER INSERT
AS
BEGIN
INSERT INTO EmployeeLog (EmployeeID, LogDate)
SELECT EmployeeID, GETDATE() FROM inserted;
an
END;
m
e
FROM Employees
WHERE Age > 30;
sd
Q15. Difference between INNER JOIN and OUTER JOIN:
i_
● INNER JOIN: Returns only the rows that have matching values in both tables.
● OUTER JOIN: Returns all rows from one table and the matched rows from the other
sh
table. If no match exists, NULL is returned for unmatched rows.
● Achieved using a junction table (also known as a linking or bridge table) that holds
foreign keys referencing the primary keys of the two related tables.
● UNION: Combines the results of two or more SELECT queries and removes duplicate
rows.
● UNION ALL: Combines the results of two or more SELECT queries without removing
duplicates.
e
UNION
SELECT Name FROM Suppliers WHERE Country = 'USA'; -- UNION (removes duplicates)
sd
SELECT Name FROM Customers WHERE Country = 'USA'
UNION ALL
SELECT Name FROM Suppliers WHERE Country = 'USA'; -- UNION ALL (includes
duplicates)
i_
sh
Q21. Indexing and Its Types:
○ Unique Index: Ensures that the indexed column(s) contain unique values.
systems).
● OLAP (Online Analytical Processing): Designed for query and analysis rather than
transaction processing, involving complex queries that aggregate data (e.g., data
warehousing).
● Used to group rows that have the same values in specified columns into summary rows,
such as counting the number of rows in each group.
SELECT Department, COUNT(*) AS EmployeeCount
FROM Employees
GROUP BY Department;
● A situation where two or more transactions are waiting for each other to release
resources, leading to a standstill. It can be avoided by using timeout, deadlock detection,
e
or ordering resources.
sd
Q25. Database Sharding:
● A method of partitioning data into smaller, more manageable pieces called shards, which
i_
are distributed across multiple servers. It improves scalability and performance by
distributing the load and enabling parallel processing.
sh
an
m
hi
@