0% found this document useful (0 votes)
5 views7 pages

DBMS QP2

The document discusses SQL aggregate operators such as COUNT, SUM, AVG, MAX, and MIN, which perform calculations on multiple rows and return a single result. It also explains the concept of views in SQL, which are virtual tables created from SELECT queries to simplify data access. Additionally, it covers transaction management properties (ACID), conflict serializability, and the differences between serial and non-serial schedules in database management systems.

Uploaded by

Tejas61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

DBMS QP2

The document discusses SQL aggregate operators such as COUNT, SUM, AVG, MAX, and MIN, which perform calculations on multiple rows and return a single result. It also explains the concept of views in SQL, which are virtual tables created from SELECT queries to simplify data access. Additionally, it covers transaction management properties (ACID), conflict serializability, and the differences between serial and non-serial schedules in database management systems.

Uploaded by

Tejas61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Q1 Whataggregate operators does sql support?

explain an
example ? in DBMS

In SQL, aggregate operators are used to perform calculations on multiple rows of a


table and return a single result. These operators are often used in conjunction with
the GROUP BY clause to group rows and then apply the aggregation on each group.

Here are the most common aggregate operators SQL supports:

SQL Aggregate Operators

COUNT()

Returns the number of rows that match a specified condition.

Example: COUNT(*) counts all rows, while COUNT(column_name)


counts non-NULL values in the column.

SUM()

Calculates the total sum of a numeric column.

Example: SUM(salary) adds up all the salary values in a column.

AVG()

Returns the average value of a numeric column.

Example: AVG(age) calculates the average age of all employees.

MAX()

Returns the maximum value from a column.

Example: MAX(salary) gets the highest salary in the salary column.

MIN()

Returns the minimum value from a column.

Example: MIN(salary) gets the lowest salary in the salary column.

Example:

Suppose we have the following Employee table:


Employe Nam Salar Departm
eID e y ent
5000
101 Alice HR
0
6000
102 Bob IT
0
Caro 4500
103 HR
l 0
7000
104 Dave IT
0

Q2. what is views how can it be created explain with an example

A View is a virtual table based on the result of an SQL SELECT query.

It does not store data physically; it just shows data from one or more underlying
tables.

Views are used to simplify complex queries, improve security, and hide specific
data from user

Syntax to Create a View:

CREATE VIEW view_name AS

SELECT column1, column2, ...

FROM table_name

WHERE condition;

Example:

Suppose we have a table:

Employee Table:

Emp Nam Salar Departm


ID e y ent
5000
1 Alice HR
0
6000
2 Bob IT
0
Caro 4500
3 HR
l 0
7000
4 Dave IT
0

Task: Create a View to show only IT Department employees


CREATE VIEW IT_Employees AS

SELECT EmpID, Name, Salary

FROM Employee

WHERE Department = 'IT';

Now, when you query this view:

SELECT * FROM IT_Employees;

OUTPUT :-

Emp Na Salar
ID me y
2 Bob 60000
Dav
4 70000
e

Q3. Write a sql query to retive the sales_id and total_price from
sales tables from the sales made on Jan 3 2024
Realtion(sales_id,product_in,quantity_Sold,sale_date,total_price)

SELECT sales_id, total_price

FROM sales

WHERE sale_date = '2024-01-03';

1. Total Price for Each Sale on Jan 3, 2024

SELECT sales_id, total_price

FROM sales

WHERE sale_date = '2024-01-03';

2. Total Sales Amount on Jan 3, 2024

SELECT SUM(total_price) AS total_sales

FROM sales

WHERE sale_date = '2024-01-03';

Result Example:
total_sale
s
125000

3. Total Sales per Sale ID on Jan 3, 2024

(If multiple entries per sales_id exist)

SELECT sales_id, SUM(total_price) AS total_sales

FROM sales

WHERE sale_date = '2024-01-03'

GROUP BY sales_id;

Result Example :-

sales_i total_sale
d s
101 30000
102 95000

Q4. Explain in detail ACID Properites of transction Management

What is a Transaction in DBMS?

A transaction is a single logical unit of work that may involve one or more database
operations (like insert, update, delete).
Example: Transferring money from Account A to Account B involves debiting A and
crediting B — both must succeed together.

ACID Properties – Full Form & Meaning

A stands for Atomicity, which means a transaction must be treated as a single unit.
Either all its operations are completed successfully, or none are applied at all. If any
step fails, the whole transaction is rolled back.
C stands for Consistency, which ensures that the database remains in a valid state
before and after the transaction. All integrity constraints must be preserved.
I stands for Isolation, meaning that concurrent transactions are executed
independently without interfering with each other. The intermediate state of a
transaction must not be visible to others.
D stands for Durability, which guarantees that once a transaction is committed, its
changes are permanently saved in the database, even in case of system failures.
Together, ACID properties maintain the accuracy, safety, and integrity of database
operations.
Q5. Describe Conflict serliazability with an example in DBMS

Conflict Serializability – Definition

Conflict Serializability is a type of schedule (sequence of transactions) in DBMS that


ensures the concurrent execution of transactions results in the same outcome as
some serial (one-by-one) execution of those transactions.

A schedule is conflict serializable if it can be transformed into a serial schedule by


swapping non-conflicting operations.

Conflicting Operations

Two operations conflict if:

They belong to different transactions.

They access the same data item.

At least one of them is a write operation.

Example:

Let's say we have two transactions:

T1: Reads and Writes on A

T2: Reads and Writes on A

T1: Read(A)

T2: Read(A)

T1: Write(A)

T2: Write(A)

This schedule is not conflict serializable because:

T1: Write(A) conflicts with T2: Read(A) and T2: Write(A)

T2: Write(A) also conflicts with T1: Write(A)

The order of conflicting operations cannot be changed to make it behave like


a serial schedule (either T1→T2 or T2→T1)

Now a Conflict Serializable Schedule:


T1: Read(A)
T1: Write(A)
T2: Read(A)
T2: Write(A)
Here, all of T1’s operations come before T2’s, so it is conflict
serializable, equivalent to the serial schedule T1 → T2.

Q6 Serial vs Non-Serial Schedule in DBMS

Feature Serial Schedule Non-Serial Schedule


A schedule where
A schedule where
transactions are
operations of
Definition executed one after
transactions are
another, without
interleaved or mixed.
interleaving.
No concurrency – only Allows concurrency –
Concurrency one transaction runs at multiple transactions
a time. run simultaneously.
Simple and easy to
More complex due to
Complexity understand and
interleaving operations.
implement.
Faster as it allows
Slower due to no
Performance overlapping of
parallel execution.
operations.
No risk of conflicts, as
Risk of Possible conflicts if not
transactions do not
Conflicts managed properly.
overlap.
T1 completes → then T2 T1 and T2 operations
Example
starts. alternate or mix.
Common in modern
Usage in Real Rarely used alone in
DBMS with proper
Systems real-time systems.
control techniques.
Need for
Not needed (already Must ensure conflict or
Serializability
serial). view serializability.
Check

You might also like