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

DBMS Exam Preparation

The document provides SQL exam preparation materials, including sample queries for retrieving sales data, using aggregate functions, creating views, and performing join operations. It also discusses SQL data types, DDL and DML commands with examples, and explains the concept of conflict serializability in transaction management. Each section includes explanations and corresponding SQL code snippets for clarity.

Uploaded by

ajp13052004
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)
2 views4 pages

DBMS Exam Preparation

The document provides SQL exam preparation materials, including sample queries for retrieving sales data, using aggregate functions, creating views, and performing join operations. It also discusses SQL data types, DDL and DML commands with examples, and explains the concept of conflict serializability in transaction management. Each section includes explanations and corresponding SQL code snippets for clarity.

Uploaded by

ajp13052004
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
You are on page 1/ 4

DBMS Exam Preparation

4. Write a SQL query to retrieve the sale_id and total_price from the
Sales table for sales made on January 3, 2024.

Explanation:
- We need to filter records from the `Sales` table where the `sale_date`
is January 3, 2024.
- The query will use the `SELECT` statement with a `WHERE` clause
to filter the date.

Exam Answer:
```sql
CREATE DATABASE SalesDB;
USE SalesDB;

CREATE TABLE Sales (


Sale_id INT PRIMARY KEY,
product_id INT,
quantity_sold INT,
sale_date DATE,
total_price DECIMAL(10,2)
);

SELECT Sale_id, total_price FROM Sales WHERE sale_date =


'2024-01-03';
```
------------------------------------

5. What aggregate operators does SQL support? Explain with an


example.

Explanation:
- SQL supports aggregate functions to perform calculations on
multiple rows.
- Common aggregate operators:
1. **SUM()** -> Adds values.
2. **AVG()** -> Calculates average.
3. **COUNT()** -> Counts rows.
4. **MAX()** -> Finds maximum value.
5. **MIN()** -> Finds minimum value.

Exam Answer:
```sql
SELECT COUNT(*) AS total_sales, SUM(total_price) AS total_revenue
FROM Sales;
```
------------------------------------

6. What is a view? How can it be created? Explain with an example.

Explanation:
- A **view** is a virtual table based on the result of an SQL query.
- It is used to simplify complex queries and enhance security.

Exam Answer:
```sql
CREATE VIEW SalesSummary AS
SELECT Sale_id, product_id, total_price FROM Sales;

SELECT * FROM SalesSummary;


```
------------------------------------

7. Explain join operations with an example?

Explanation:
- Joins combine rows from two or more tables based on a related
column.
- Types of Joins:
1. **INNER JOIN** -> Matches rows in both tables.
2. **LEFT JOIN** -> All rows from the left table + matching rows from
the right table.
3. **RIGHT JOIN** -> All rows from the right table + matching rows
from the left table.
4. **FULL JOIN** -> All rows from both tables.

Exam Answer:
```sql
SELECT Sales.Sale_id, Sales.total_price, Salesman.name
FROM Sales
INNER JOIN Salesman ON Salesman.salesman_id = Sales.Sale_id;
```
------------------------------------

8. Discuss different SQL datatypes?

Explanation:
- **Numeric Types:** `INT`, `DECIMAL`, `FLOAT`
- **String Types:** `VARCHAR`, `TEXT`
- **Date/Time Types:** `DATE`, `DATETIME`
- **Boolean Type:** `BOOLEAN`

------------------------------------

9. Explain different DDL & DML commands with examples?

Explanation:
- **DDL (Data Definition Language):** Defines structure (`CREATE`,
`ALTER`, `DROP`).
- **DML (Data Manipulation Language):** Modifies data (`INSERT`,
`UPDATE`, `DELETE`).

Exam Answer:
```sql
-- DDL Example
CREATE TABLE Customers (
customer_id INT PRIMARY KEY,
name VARCHAR(100)
);

-- DML Example
INSERT INTO Customers VALUES (1, 'Alice');
UPDATE Customers SET name = 'Bob' WHERE customer_id = 1;
DELETE FROM Customers WHERE customer_id = 1;
```
------------------------------------

10. Describe Conflict Serializability with an example.

Explanation:
- Conflict Serializability ensures that a given schedule can be
transformed into a serial schedule by swapping non-conflicting
operations.
- Two operations conflict if:
1. They belong to different transactions.
2. They access the same data.
3. At least one of them is a write operation.

Exam Answer:
A schedule is **Conflict Serializable** if it can be transformed into a
serial schedule by swapping non-conflicting operations.

Example:
Consider two transactions, **T1** and **T2**:

| Time | Transaction | Operation |


|------|------------|-----------|
| 1 | T1 | Read(A) |
| 2 | T2 | Read(A) |
| 3 | T1 | Write(A) |
| 4 | T2 | Write(A) |

Since `T1` and `T2` both **read and write A**, a **conflict** exists. By
drawing a **precedence graph**, if a cycle is found, the schedule is
**not conflict serializable**.

------------------------------------

You might also like