DBMS_Interview_Questions
DBMS_Interview_Questions
1. What is DBMS and what are its advantages over file systems?
A Database Management System (DBMS) is software designed to store, retrieve, define, and
manage data in a database.
1. One-to-One (1:1)
One record in Table A matches exactly one record in Table B
Example: Person and Passport Number
```sql
Person(ID, Name, PassportID)
Passport(PassportID, IssueDate, ExpiryDate)
```
2. One-to-Many (1:N)
One record in Table A can match many records in Table B
Example: Department and Employees
```sql
Department(DeptID, DeptName)
Employee(EmpID, Name, DeptID)
```
3. Many-to-Many (M: N)
Multiple records in Table A can match multiple records in Table B
Example: Students and Courses
```sql
Student(StudentID, Name)
Course(CourseID, CourseName)
StudentCourse(StudentID, CourseID)
```
Example:
```sql
-- Primary Key
DeptName VARCHAR(50)
);
-- Foreign Key
Name VARCHAR(50),
DeptID INT,
);
```
```sql
```
```sql
```
3. DCL (Data Control Language)
- GRANT, REVOKE
```sql
```
```sql
BEGIN TRANSACTION;
COMMIT;
```
ACID Properties:
Example:
```sql
BEGIN TRANSACTION;
COMMIT;
7. What are joins in SQL? Explain different types with examples
Answer:
1. INNER JOIN
```sql
FROM Employee e
```
2. LEFT JOIN
```sql
FROM Employee e
```
3. RIGHT JOIN
```sql
FROM Employee e
```
4. FULL JOIN
```sql
FROM Employee e
```
8. What is an index? What are its types?
Answer: An index is a data structure that improves the speed of data retrieval operations.
Types:
1. Single-Column Index
```sql
```
2. Composite Index
```sql
```
3. Unique Index
```sql
```
Example:
```sql
FROM Employee e
```
Differences:
Example:
```sql
BEGIN
END;
```
Example:
```sql
@DeptID INT
AS
BEGIN
FROM Employee
WHERE DeptID = @DeptID;
END;
```
Prevention:
```sql
-- Use timeout
```
```sql
```
14. What are aggregate functions? Give examples
Answer: Aggregate functions perform calculations on a set of values.
Examples:
```sql
SELECT
COUNT(*) as TotalEmployees,
AVG(Salary) as AvgSalary,
MAX(Salary) as MaxSalary,
MIN(Salary) as MinSalary,
SUM(Salary) as TotalSalary
FROM Employee;
```
Example:
```sql
SELECT Name
FROM Employee
SELECT AVG(Salary)
FROM Employee
);
```
);
```
```sql
FROM Employee
GROUP BY DeptID
```
Example:
```sql
ID INT,
SaleDate DATE,
Amount DECIMAL
);
```
```sql
UNION
UNION ALL
```
Types of Backups:
1. Full Backup:
```sql
TO DISK = 'D:\Backups\EmployeeDB.bak';
```
2. Differential Backup:
```sql
TO DISK = 'D:\Backups\EmployeeDB_Diff.bak'
WITH DIFFERENTIAL;
```
Recovery:
```sql
```