0% found this document useful (0 votes)
6 views

Dbms Assign

The document discusses SQL queries to retrieve employee information from various tables. It contains queries to find employee names and locations for a particular company, employees that do not work for a company, highest paid employees, and employees paid more than another company.

Uploaded by

brunodash1455
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Dbms Assign

The document discusses SQL queries to retrieve employee information from various tables. It contains queries to find employee names and locations for a particular company, employees that do not work for a company, highest paid employees, and employees paid more than another company.

Uploaded by

brunodash1455
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

a.

Find the names of all employees who work for First Bank Corporation:
SQL
SELECT person_name
FROM Works
WHERE company_name = 'First Bank Corporation';

b. Find the names and cities of residences of all employees who work for First Bank
Corporation:
SQL
SELECT E.person_name, E.city
FROM Employee E
JOIN Works W ON E.person_name = W.person_name
WHERE W.company_name = 'First Bank Corporation';

c. Find the names of all employees who do not work for First Bank Corporation:
SQL
SELECT person_name
FROM Employee
WHERE person_name NOT IN (
SELECT person_name
FROM Works
WHERE company_name = 'First Bank Corporation'
);

d. Find names of all employees who earn more than $10000 per annum:
SQL
SELECT person_name
FROM Works
WHERE salary > 10000;

e. Find names of all employees who earn more than every employee of Small Bank
Corporation:
SQL
SELECT W1.person_name
FROM Works W1
WHERE W1.salary > ALL (
SELECT W2.salary
FROM Works W2
WHERE W2.company_name = 'Small Bank Corporation'
);
a. Find the name of suppliers who supply some red parts:
SQL
SELECT DISTINCT sname
FROM Suppliers S
JOIN Catalog C ON S.sid = C.sid
JOIN Parts P ON C.pid = P.pid
WHERE P.color = 'red';

b. Find the sids of suppliers who supply some red or green parts:
SQL
SELECT DISTINCT S.sid
FROM Suppliers S
JOIN Catalog C ON S.sid = C.sid
JOIN Parts P ON C.pid = P.pid
WHERE P.color IN ('red', 'green');

c. Find the sids of suppliers who supply some red part or are at 221 Packer Ave:
SQL
SELECT DISTINCT S.sid
FROM Suppliers S
JOIN Catalog C ON S.sid = C.sid
JOIN Parts P ON C.pid = P.pid
WHERE P.color = 'red'
OR S.address = '221 Packer Ave';

Ans3.-
To convert the given relation R(A, B, C, D, E, F) into 2NF (Second Normal Form), we need to
follow these steps:
1. Identify the functional dependencies (FDs) in the given set:
o AB → C
o C → DE
o E→F
o F→B
2. Determine the candidate keys for the relation. A candidate key is a minimal set of
attributes that uniquely identifies each tuple in the relation. In this case, the candidate
keys are {AB} and {CF}.
3. Check if the relation is already in 2NF. A relation is in 2NF if:
o It is in 1NF (which means all attributes are atomic).
o Every non-prime attribute (attributes not part of any candidate key) is fully
functionally dependent on the entire candidate key.
4. Let’s analyze the given FDs:
o AB → C: C is a non-prime attribute and is not fully functionally dependent on the
entire candidate key {AB}.
o C → DE: DE are non-prime attributes and are not fully functionally dependent on
the entire candidate key {CF}.
o E → F: F is a non-prime attribute and is not fully functionally dependent on the
entire candidate key {CF}.
o F → B: B is a non-prime attribute and is not fully functionally dependent on the
entire candidate key {CF}.
5. To achieve 2NF, we need to decompose the relation into smaller relations. Let’s create
two new relations:
o Relation 1: R1(A, B, C)
o Relation 2: R2(C, D, E, F)
6. The attributes in each relation are as follows:
o R1: A, B, C
o R2: C, D, E, F
7. Now let’s check if both R1 and R2 are in 2NF:
o R1:
 AB → C (C is fully functionally dependent on the candidate key {AB}).
 No partial dependencies.
 R1 is in 2NF.
o R2:
 C → DE (DE are fully functionally dependent on the candidate key {CF}).
 E → F (F is fully functionally dependent on the candidate key {CF}).
 No partial dependencies.
 R2 is in 2NF.
8. Therefore, the given relation is now in 2NF after decomposition.

The resulting relations are:

 R1(A, B, C) with the FD AB → C


 R2(C, D, E, F) with the FDs C → DE and E → F

These relations satisfy the requirements of 2NF. 📊

Ans4-
Let’s analyze the given relation R(A, B, C, D, E, F) and the set of functional dependencies (FDs):
1. Functional Dependencies (FDs):
o AB → C
o C→D
o D→E
o E→F
o F→A
2. Candidate Keys:
o The candidate keys are {AB} and {CF}.
3. Check for 3NF:
o To determine if the relation is in 3NF, we need to check if it satisfies the following
conditions:
 It is in 2NF.
 Every non-prime attribute (attributes not part of any candidate key) is
fully functionally dependent on the entire candidate key.
4. Partial Dependencies:
o AB → C: C is a non-prime attribute and is not fully functionally dependent on the
candidate key {AB}.
o C → D: D is a non-prime attribute and is not fully functionally dependent on the
candidate key {CF}.
o D → E: E is a non-prime attribute and is not fully functionally dependent on the
candidate key {CF}.
o E → F: F is a non-prime attribute and is not fully functionally dependent on the
candidate key {CF}.
o F → A: A is a non-prime attribute and is not fully functionally dependent on the
candidate key {CF}.
5. Decomposition into 3NF:
o We need to create two new relations:
 R1(A, B, C) with the FD AB → C
 R2(C, D, E, F) with the FDs C → D, D → E, and E → F
6. Resulting Relations:
o R1(A, B, C):
 AB → C (C is fully functionally dependent on the candidate key {AB}).
o R2(C, D, E, F):
 C → D (D is fully functionally dependent on the candidate key {CF}).
 D → E (E is fully functionally dependent on the candidate key {CF}).
 E → F (F is fully functionally dependent on the candidate key {CF}).
7. Therefore, the given relation is now in 3NF after decomposition.

Ans5-
A transaction in the context of databases refers to a sequence of one or more operations (such
as reading or writing data) that are executed as a single unit of work. Transactions ensure data
consistency, integrity, and reliability in a database system. Let’s delve into the ACID
properties associated with transactions:
1. Atomicity (A):
o Atomicity ensures that a transaction is treated as an indivisible unit. Either all its
operations are successfully completed, or none of them take effect.
o If any part of the transaction fails (due to an error, system crash, or other reasons),
the entire transaction is rolled back to its initial state.
o Example: A funds transfer from one bank account to another should either
complete entirely or not happen at all.
2. Consistency ©:
o Consistency ensures that a transaction transforms the database from one
consistent state to another.
o The database must satisfy all integrity constraints (such as unique keys, referential
integrity, etc.) before and after the transaction.
o Example: If a student enrolls in a course, the total number of enrolled students
should remain consistent.
3. Isolation (I):
o Isolation ensures that concurrent transactions do not interfere with each other.
o Transactions execute in isolation, as if they were the only ones running. Changes
made by one transaction are not visible to others until the transaction is
committed.
o Isolation levels (such as Read Uncommitted, Read Committed, Repeatable Read,
Serializable) control the degree of isolation.
o Example: Two users booking seats on the same flight should not accidentally
book the same seat.
4. Durability (D):
o Durability guarantees that once a transaction is committed, its effects persist even
in the face of system failures (e.g., power outage, crash).
o Committed changes are stored permanently in the database.
o Example: After a successful online purchase, the order details should remain intact
even if the server crashes.

In summary, ACID properties ensure that transactions are reliable, maintain data integrity, and
provide predictable behavior in a multi-user database environment

Ans6-
Let’s analyze the given schedules S1 and S2 to determine if they are conflict serializable:
1. Schedule S1:
o R1(x), R1(y), R2(x), R2(y), W2(y), W1(x)
o The conflicting operations are:
 R1(x) and W1(x) (both access the same data item x)
 R1(y) and W2(y) (both access the same data item y)
o There is a conflict between these operations, but can we find an equivalent serial
schedule?
2. Schedule S2:
o R1(x), R2(x), R2(y), W2(y), R1(y), W1(x)
o The conflicting operations are:
 R1(x) and W1(x) (both access the same data item x)
 R1(y) and W2(y) (both access the same data item y)
o Again, there is a conflict between these operations.
3. Conflict Serializability Test:
o To check if a schedule is conflict serializable, we can construct a precedence
graph (also known as a serialization graph).
o Each transaction is represented as a node, and there is an edge from T1 to T2 if
T1 precedes T2 in the schedule.
o If the graph is acyclic, the schedule is conflict serializable.
4. Precedence Graph for S1:
o T1 (R1(x)) → T2 (R2(x)) → T2 (W2(y)) → T1 (W1(x))
o The graph is acyclic, so S1 is conflict serializable.
5. Precedence Graph for S2:
o T1 (R1(x)) → T2 (R2(x)) → T2 (W2(y)) → T1 (W1(x))
o The graph is acyclic, so S2 is also conflict serializable.

Both S1 and S2 are conflict serializable because their precedence graphs are acyclic.
Ans7-
Let’s analyze each of the given schedules to determine if they follow the principles of Two Phase
Locking (2PL):
1. Schedule S1:
o L1 (X), L1 (Y), L2 (Z), U2 (Z), U1 (Y), U1 (X)
o This schedule follows 2PL because it adheres to the two-phase locking protocol:
 All locks are acquired before any unlock operation.
 No unlock operation occurs before all locks are acquired.
o Therefore, S1 follows 2PL.
2. Schedule S2:
o L1 (X), U1 (X), L1 (Y), L2 (Z), U2 (Z), U1 (Y)
o This schedule violates 2PL because transaction 1 releases a lock (U1(X)) before
acquiring all its locks.
o Therefore, S2 does not follow 2PL.
3. Schedule S3:
o L1 (X), U1 (X), L1 (Y), U1 (Y), L2 (Z), U2 (Z)
o This schedule follows 2PL because all locks are acquired before any unlock
operation.
o Therefore, S3 follows 2PL.
4. Schedule S4:
o L1 (X), L1 (Y), L2 (Z), U2 (Z), U1 (Y), U1 (X), L2 (X), U2 (X)
o This schedule violates 2PL because transaction 2 acquires a new lock (L2(X)) after
releasing a lock (U2(Z)).
o Therefore, S4 does not follow 2PL.

In summary:

 S1 and S3 follow the principles of Two Phase Locking.


 S2 and S4 do not follow the principles of Two Phase Locking

You might also like