Important RDBMS
Important RDBMS
answers:
---
Indexing improves database performance by allowing quicker data retrieval without scanning the
entire table. An index creates a data structure (like a B-Tree) that provides a fast lookup mechanism.
- **Clustered Index**: Stores rows in the table based on key values; only one is allowed per table.
- **Non-Clustered Index**: A separate structure pointing to the table rows; multiple non-clustered
indexes are allowed.
- **Unique Index**: Ensures all values in the index column are unique.
---
**Causes**:
- Use performance monitoring tools like **SQL Profiler**, **Performance Monitor**, or **EXPLAIN
plans**.
- Look for metrics like CPU utilization, query execution time, or I/O operations.
---
### **3. Connection Pooling**
**Definition**:
Connection pooling involves reusing existing database connections instead of creating a new one for
every user request.
---
1. **Full Backup**:
- **Advantages**: Captures entire data; simple to restore.
2. **Incremental Backup**:
3. **Differential Backup**:
- **Advantages**: Backs up changes since the last full backup; quicker restore than incremental.
---
### **5. Tools and Techniques for Backup Monitoring and Recovery**
- **Tools**: SQL Server Management Studio (SSMS), Oracle RMAN, pgAdmin for PostgreSQL.
- **Techniques**:
---
**Identification**:
- Analyze execution plans.
- Look for slow queries using tools like SQL Profiler or `EXPLAIN`.
**Example**:
- **Bottleneck**: A full table scan in a query.
```sql
```
```sql
```
---
**Considerations**:
**Definition**:
A view is a virtual table based on a query. It does not store data but simplifies complex queries.
#### **Advantages**:
1. Simplifies query writing.
**Example**:
```sql
```
---
These answers cover key points concisely for 3-mark questions. Let me know if further elaboration is
needed!
Here's an explanation of the questions, structured for clarity and aligned with T-SQL concepts:
---
**Joins** are used to combine rows from two or more tables based on related columns.
```sql
FROM Employees
INNER JOIN Departments ON Employees.DeptID = Departments.DeptID;
```
2. **Left Join** (Outer Join): Returns all rows from the left table and matching rows from the right
table, with `NULL` for non-matches.
```sql
SELECT Employees.Name, Departments.DeptName
FROM Employees
```
3. **Right Join**: Similar to Left Join but for the right table.
4. **Full Outer Join**: Returns all rows when there is a match in either table.
5. **Cross Join**: Returns the Cartesian product of both tables.
#### **Importance**:
Joins are essential for creating relationships between tables and retrieving combined data efficiently.
---
A **cursor** is a database object used to retrieve, manipulate, and iterate through query result sets
row by row.
#### **When to Use Cursors**:
- Use only when row-by-row processing is unavoidable (e.g., for batch updates where set-based
operations are impractical).
**Example**:
```sql
OPEN cursor_example;
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT @Name;
FETCH NEXT FROM cursor_example INTO @Name;
END;
CLOSE cursor_example;
DEALLOCATE cursor_example;
```
---
**Example**:
```sql
RETURNS INT
AS
BEGIN
IF @Number <= 1
RETURN 1;
END;
-- Usage:
---
```sql
```
```
```
---
### **5. Optimizing Query Performance in T-SQL**
**Methods**:
**Example**:
Without an index:
```sql
```
```sql
```
---
**Definition**:
**Advantages**:
**Example**:
```sql
CREATE PROCEDURE GetEmployeeDetails
@EmployeeID INT
AS
BEGIN
END;
-- Usage:
```
---
**Definition**:
Triggers are special types of stored procedures that automatically execute in response to events
(INSERT, UPDATE, DELETE) on a table.
**Example**:
```sql
AFTER INSERT
AS
BEGIN
END;
```
---
Contains additional metadata, like variable types, symbol table references, and semantic rules.
---
This covers all the questions comprehensively. Let me know if you'd like further clarification on any
point!