Exam Flashcards

1
Q

What is a Data Model?

a. A model describing data.
b. A collection of concepts describing data.
c. A description of a collection of data.
d. A collection of schemas describing data.

A

b. A collection of concepts describing data.

Explanation: A Data Model is a collection of multiple concepts that describe the data. A single concept does not explain all tables, thus it needs to be a collection of multiple.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Owner entity is associated with one or more weak entities, but each weak entity
has a single owner.This relationship set is called the ________ set of the weak entity
set.

a. Independent Relationship
b. Total Participation
c. Identifying Relationship
d. None of the above

A

Identifying Relationship

Explanation: An identifying relationship is a relationship between two entities in
which an instance of a weak entity is identified through its association with an owner
entity, which means the weak entity is based on the owner entity for its identity and
cannot exist without it.

Note: Lets say we have an entity(table) Person, which have an attribute(ID). If there would be another entity, such as a child we could note the child entity as a weak entity as the child can not be identified without it’s parent entity(Person). Therefore we need an IDENTIFYING relationship to identify to which Person this child belongs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Given table : | StudentID | CourseID | StartDate | EndDate |

Which aggregate function will NOT generate an error on the StartDate(datatype :

date) column?
a. COUNT(StartDate)
b. AVG(StartDate)
c. SUM(StartDate)
d. All of the above

A

d. All of the above

Explanation: All of the functions that are mentioned in the options run and give you
a value for StartDate with data type date.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Modify the ‘Student’ table to add a primary key on the StudentID column. We
assume that the table is currently empty.

Given table : | StudentID | CourseID | StartDate | EndDate |

Which statement is correct in order to perform this task?
a. ALTER TABLE Student
ADD PRIMARY KEY StudentID;
b. MODIFY TABLE Student
ADD CONSTRAINT PRIMARY KEY (StudentID);
c. ALTER TABLE Student
ADD CONSTRAINT StudentID_PK PRIMARY KEY (StudentID);
d. MODIFY TABLE Student
ADD CONSTRAINT StudentID_PK PRIMARY KEY StudentID;

A

c. ALTER TABLE Student
ADD CONSTRAINT StudentID_PK PRIMARY KEY (StudentID);

Explanation: This question is a syntax question where the only right option is to use
the ALTER command and remembering to use the ADD CONSTRAINT

Note: ALTER TABLE is used for altering a table means to change column name, size, drop column. CHANGE COLUMN and MODIFY COLUMN commands cannot be used without help of ALTER TABLE command.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Given these tables:
Sailor (SID, NAME, RATING, AGE)
Boat (BID, NAME, SIZE, COLOR)
WorksOn (SID, BID)

What is the result of this expression: (∀B | ¬ (B ∈Boat)) ?

a. This query will give a list of all fields from Boat table
b. This query has infinite results.
c. This query will only give a list of Boat ID
d. This query will evaluate to NULL

A

b. This query has infinite results.

Explanation: The query asks for all B such that B is not in Boats. That is infinite.

Note: (∀B | ¬ (B ∈Boat)) = (For all boats | Not (Boats in Boat))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
Given these tables:
Sailor (SID, NAME, RATING, AGE)
Boat (BID, NAME, SIZE, COLOR)
WorksOn (SID, BID)
What will this expression give:

{P / ∃B ∈ Boat ( B.SIZE >7 ∧ B.COLOR = ’Blue’ ∧ P.BID = B.BID)}

a. All fields from Boat where size > 7 or Color = Blue
b. Size and Name from Boat where size > 7 and Color = Blue
c. Size and Name from Boat where size > 7 or Color = Blue
d. Only the Primary Key BID from Boat where size > 7 and Color = Blue

A

d. Only the Primary Key BID from Boat where size > 7 and Color = Blue

Explanation: Here the conditions are color must be blue AND size should be more
than 7. Also, only the BID column is ‘copied’ to the set P that is returned. So d is
true.

Note: {P / ∃B ∈ Boat ( B.SIZE >7 ∧ B.COLOR = ’Blue’ ∧ P.BID = B.BID)}

= Find all P where there exists BOATS in BOAT where boatsize is > 7 and boatcolor is Blue and obtain only the BID column.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Given these tables:
Sailor (SID, NAME, RATING, AGE)
Boat (BID, NAME, SIZE, COLOR)
WorksOn (SID, BID)

Which of the following statements is true for a superkey for the table Sailor?
a. SID is the only superkey
b. If and only if all sailors names were unique, SID, NAME together could form a
superkey
c. SID,NAME,RATING,AGE is a valid superkey
d. There is no superkey in this table.

A

c. SID,NAME,RATING,AGE is a valid superkey

Explanation: A superkey uniquely identifies a record of a table, but does not have to
be minimal. In this case, for the table Sailor any key that includes SID (the primary
key) is a superkey. So, c is the answer.

Note: Other superkeys would be (SID,NAME), (SID, RATING), (SID, AGE), (SID, NAME, RATING) and so on.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Given a table ABCD, which of the following is a lossless join decomposition?

AB is the primary key

a. R1= ACD, R2, ABC
b. R1= ABC, R2= ABD
c. R1= AB, R2= CD
d. R1= ABC, R2= AD

A

a. R1= ACD, R2, ABC - CORRECT
b. R1= ABC, R2= ABD - CORRECT
c. R1= AB, R2= CD - WRONG
d. R1= ABC, R2= AD - CORRECT

Explanation: A decomposition {R1 , R2} of R is lossless if and only if the common attributes of R1 and R2 form a superkey for either schema, that is
•R1 ∩ R2→R1
OR
•R1 ∩ R2→R2

As we can see, R1 and R2 in c., do not share common attribute.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which of the following is an example of a trivial functional dependency?

a. X → A where A∈X
b. X → A, X → B, then X → AB
c. If X → Y, then XZ → YZ
d. X → Y , Y → Z then Z → X

A

a. X → A where A∈X

Explanation: The Trivial dependency is a set of attributes which are called a trivial if the set of attributes are included in that attribute.
So, X -> Y is a trivial functional dependency if Y is a subset of X.

Note: (X determines A) where (A is an element/subset of X)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which of the following is NOT a problem that is associated with decomposition
and schema normalization?

a. Queries may become more expensive, as they may need joining decomposed
relations
b. Decomposition may cause loss of data tuples from the relations
c. Decomposition may introduce extra tuples from the relation.
d. Decomposition may cause us to lose functional dependencies from the
original relation.

A

b. Decomposition may cause loss of data tuples from the relations

Explanation: Decomposition breaks the table into parts. If a query then needs to use data from the decomposed tables, adding a join may make it more expensive.
Thus, a is true. C and D correspond to lossless join decomposition and dependency preserving decomposition. b is false (and is the answer)
See lecture 10 slides 27-31

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Convert the following functional dependencies into minimal cover: A→B, AB→C

a. It is already a minimal cover
b. A→B, A→C
c. A→C, B→C
d. None of these

A

b. A→B, A→C

Explanation: A→B, AB→C is given. As we can get B from A (A→B), so in AB→C, B
on the left side is not necessary. So can be removed in the minimal form, giving us (b) as the answer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which of the following statements about using indexes in MySQL is true?

a. Indexes can only be created on individual columns, not a combination of
columns.
b. Doubling the number of indexes in a MySQL database speeds up update
operations tenfold times.
c. It is not possible to create more than one index on the same table in MySQL
database.
d. None of the above

A

d. None of the above

Option D: Correct because it is possible to make a combination of indexes and more than one index can be created on the same table.
Doubling the number of indexes in a MySQL database doesn’t speed up update operations tenfold times.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Consider a B+ tree in which the maximum number of keys in a node is 7. What is the minimum number of keys in any non-root node?

a. 1
b. 2
c. 3
d. 4

A

c. 3

Explanation:
maximum number of keys = 7
order = 7 + 1 = 8
keys = (order / 2) - 1 = (8/2) - 1 = 3

Note:
Order m = 7
Max Child = m = 7
Min Child = ceil(m/2) = 4
Max keys = m - 1  = 6
Min keys = ceil(m/2) - 1 = ceil(3.5) - 1 = 4 - 1 = 3.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The unit of information read from and written to disk is a _________

a. Leaf
b. Page
c. Attribute
d. Value

A

b. Page

Option B: Correct. A page is a basic unit of I/O operation that stores every piece of data in SQL Server.

Note: Leaf is something that belongs to a tree data structure.
Attribute is the same as a column name attatched to an entity
A value could be something attached to a key in a key-value pair.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Suppose we have two transactions T1 and T2, the operation nr indicates when the operations run.
X and Y start as X = 500, Y=500.
After the two transactions X = 550, Y = 450 and Z = 1050.
Which ACID principle is violated?

Operation nr 
T1\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_T2
1 READ(X)
2 X := X+50
3 WRITE(X)
4 READ(Y)\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_READ(X)
5 Y := Y-50\_\_\_\_\_\_\_\_\_\_\_\_\_\_READ(Y)
6 WRITE(Y)\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Z := X+Y
7\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_WRITE(Z)

a. A
b. C
c. I
d. D

A

c. I

Explanation: As described in the text the result of the transaction is X=550, Y=450
z=1050. In line 5 Y is written and Y is used in T2. This results in an Isolation
violation.

Note: A - The entire transaction took place
C - The database is consistent before and after the transaction
I - The Y transaction in T1 was NOT isolated which violated this principle.
D - There was no failure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

ACID, What does the C mean?

a.Consistency;The database must be consistent before and after a
transaction.
b. Cooperative; All systems in the DBMS work together in a transparent way to
the user.
c. Concise; All transactions are minimized to the minimum operations that still
perform the desired task.
d. Catalog; The DBMS maintains a catalog consisting of metadata.

A

a.Consistency;The database must be consistent before and after a
transaction.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

ACID, What does the I mean?
a. Integrity; The database maintains integrity.
b.Isolation;Multiple Transactions occur independently without
interference.
c. Inversion; DBMS transactions are reversible.
d. Inference; The DBMS should always be able to infer lost data.

A

b.Isolation;Multiple Transactions occur independently without
interference.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Consider the following sequence of actions; What does the ROLLBACK do ?
TRANSACTION …
COMMIT;
ROLLBACK;

a. Undoes the committed changes.
b. Commits the changes and makes its changes permanent.
c. Nothing.
d. Recommits the changes

A

c. Nothing.

Explanation: In this case the commit happens before the rollback. This means that the rollback has nothing to do

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

We have the table below Customers. You need to create a couple of stored
procedures.

pid pname ptlf pemail page
1 Mark 90000001 mark@email.com 22
2 Maria 90000002 maria@email.com 23

Create a stored procedure that retrieves the customers that are older
than the input variable age. (2)

A
DELIMITER \$\$
CREATE PROCEDURE getCostumerWithAge(IN Age INT)
BEGIN
START TRANSACTION;
GET * FROM Customers WHERE page > Age
COMMIT;
END\$\$
DELIMITER ;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

We have the table below Customers. You need to create a couple of stored
procedures.

pid pname ptlf pemail page
1 Mark 90000001 mark@email.com 22
2 Maria 90000002 maria@email.com 23

DELIMITER \$\$
CREATE PROCEDURE getCostumerWithAge(IN Age INT)
BEGIN
START TRANSACTION;
GET * FROM Customers WHERE page > Age
COMMIT;
END\$\$
DELIMITER ;

Write the query to run the stored procedure, and retrieve all the
customers that are older than 18. (2)

A

CALL getCostumerWithAge(18);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

We have the table below Customers. You need to create a couple of stored
procedures.

pid pname ptlf pemail page
1 Mark 90000001 mark@email.com 22
2 Maria 90000002 maria@email.com 23

Create a table named CustomersTest which has the same schema as
the Customers table. (1)

A

CREATE TABLE CustomersTest Like Customers;

The student can also recreate the table from scratch.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

We have the table below Customers. You need to create a couple of stored
procedures.

pid pname ptlf pemail page
1 Mark 90000001 mark@email.com 22
2 Maria 90000002 maria@email.com 23

The developers that use the table Customers, need a test table that is
larger than the current table, to test the performance. You need to
create a stored procedure that creates n number of dummy customers
that will be put into the table Customers.

A

DELIMITER $$
CREATE PROCEDURE InsertEmp(IN NumRows INT)
BEGIN
DECLARE i INT DEFAULT 1;
START TRANSACTION;
WHILE i <= NumRows DO
INSERT INTO Customers(pname, ptlf, pemail, page)
VALUES
(CAST(RAND()99999, NCHAR) , FLOOR(RAND()99999999) ,
CAST(RAND()99999, NCHAR)+”@email.com”, FLOOR(RAND()99) );
SET i = i + 1;
END WHILE;
COMMIT;
END$$
DELIMITER ;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Consider the following schema:
Suppliers( sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers.
Suppliers
sid:int 
sname:varchar(255)
address:varchar(255)

Parts

pid: int
pname: varchar(255)
color: varchar(255)

Catalog

sid: int
pid: int
cost: real

Write the following query in SQL:
a. Create the needed tables. Add the necessary constraints. (2)

A

Solution Proposal:
a. Create the needed tables. Add the necessary constraints.
First, we need to create 3 tables: Suppliers, Parts and Catalog. The Suppliers table
has 3 attributes (sid, snake, address). The Parts table has three attributes (pid,
pname, color) and the Catalog table has three attributes (sid, pid, cost).

CREATE TABLE IF NOT EXISTS Exam2021.Suppliers(
SID INT NOT NULL auto_increment,
Sname VARCHAR(25),
Address VARCHAR(50),
PRIMARY KEY (SID)
);
CREATE TABLE IF NOT EXISTS Exam2021.Parts(
PID INT NOT NULL auto_increment,
Pname VARCHAR(25),
Color VARCHAR(25),
PRIMARY KEY (PID)
);
CREATE TABLE IF NOT EXISTS Exam2021.Catalog(
SID INT NOT NULL,
PID INT NOT NULL,
Cost REAL,
FOREIGN KEY (SID) REFERENCES Suppliers(SID),
FOREIGN KEY (PID) REFERENCES Parts(PID)
);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Consider the following schema:
Suppliers( sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers.
Suppliers
sid:int 
sname:varchar(255)
address:varchar(255)

Parts

pid: int
pname: varchar(255)
color: varchar(255)

Catalog

sid: int
pid: int
cost: real

Write the following query in SQL:
How would you write queries to insert into the various tables in this database?

A

insert into Suppliers values (1, ‘Mr Meeseeks’,’Seattle’);
insert into Suppliers values (2, ‘Rick Sanchez’,’Illinois’)

insert into Parts values (1, ‘Bolt’,’Red’);
insert into Parts values (2, ‘Screw’,’Blue’);

insert into Catalog values (1, 1, 123);
insert into Catalog values (2, 2, 1200);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Consider the following schema:
Suppliers( sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers.
Suppliers
sid:int 
sname:varchar(255)
address:varchar(255)

Parts

pid: int
pname: varchar(255)
color: varchar(255)

Catalog

sid: int
pid: int
cost: real

Write the following query in SQL:
How would you write queries to find the pnames of parts for which there is some supplier.

A

Find the pnames of parts for which there is some supplier.

From lecturer answer suggestion:

SELECT Pname FROM Parts
WHERE Parts.PID = (SELECT PID FROM Catalog WHERE Catalog.PID =
Parts.PID);

I believe this is wrong, this will give error on to many rows returned for the “=” operator. The “=” should be replaced by the IN operator.

OR

SELECT pname FROM parts p INNER JOIN catalog c ON p.pid = c.pid;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

Consider the following schema:
Suppliers( sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers.
Suppliers
sid:int 
sname:varchar(255)
address:varchar(255)

Parts

pid: int
pname: varchar(255)
color: varchar(255)

Catalog

sid: int
pid: int
cost: real

Write the following query in SQL:
Find the SIDs of suppliers who supply only red parts.(2)

A

Find the sids of suppliers who supply only red parts.
SELECT DISTINCT Catalog.SID
FROM Catalog, Parts
WHERE NOT EXISTS (SELECT * FROM Parts WHERE Parts.PID = Catalog.PID
AND Parts.Color <> ‘Red’);

OR

SELECT DISTINCT c.sid FROM catalog c
INNER JOIN parts p ON p.pid = c.pid WHERE p.color = “red”;

27
Q

Consider the following schema:
Suppliers( sid: integer, sname: string, address: string)
Parts(pid: integer, pname: string, color: string)
Catalog( sid: integer, pid: integer, cost: real)

The Catalog relation lists the prices charged for parts by Suppliers.
Suppliers
sid:int 
sname:varchar(255)
address:varchar(255)

Parts

pid: int
pname: varchar(255)
color: varchar(255)

Catalog

sid: int
pid: int
cost: real

Write the following query in SQL:
Find the sids of suppliers who supply a red part or a green part.(2)

A

Find sids of suppliers who supply a red part or a green part
SELECT Catalog.SID FROM Parts, Catalog
WHERE (Parts.PID = Catalog.PID AND Parts.color = ‘Green’)
UNION (SELECT Catalog.SID FROM Parts, Catalog
WHERE(Parts.PID = Catalog.PID AND Parts.Color = ‘Red’));

28
Q

For the relation and associated dependencies given below, determine the
candidate keys and decompose into BCNF (10)
Table (S, T, V, C, D,P) with the FDs as follows
S → T
V → SC
SD→ PV

A

Solution Proposal:
D does not appear on the right hand side of any FD, so it may constitute a key.
Also, S → T and V → SC, so V → TSC
Moreover, SD → PV and V → TSC.
Thus, SD determines P,V,T,S.C, so SD is a superkey
S → T does not satisfy BCNF, so decomposing we get:
ST, SVCDP
Again, V → SC does not satisfy BCNF because it does not include D, which is
required for a key
Then decomposing we get: ST, VSC, VDP.
Now, the columns of the last FD are not in the same relation together.
Also, for all relations generated, the superkey determines all other attributes.
A lossless join decomposition into BCNF is ST, VC, VS, VDP,
another is ST, VSC,VDP

29
Q
Table A
T1\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_T2
R(x)
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_R(x)
W(x)
R(y)
\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ W(x)
W(y)

Table B
T1_________________T2________________T3
R(a)
R(b)
___________________R(a)
___________________ R(c)
W(b)
commit
_____________________________________R(b)
_____________________________________R(c)
____________________________________ W(b)
____________________________________ commit
__________________W(a)
__________________W(c)
__________________commit
Table C
T1__________________T2___________________T3
R(a)
____________________R(b)
____________________W(a)
____________________commit
W(a)
commit
________________________________________W(a)
________________________________________commit

a) Create the precedence graphs for the transactions in table A, B and C (6)
b) Are the transactions in table A, B and C Conflict Serializable, explain why. (4)

A

A is not conflict serializable
Both T1 and T2 read X, the conflict arises when both T1 and T2 write X.
B is conflict serializable
There is no conflict between T1, T2 and T3. No “overlapping” read/write conflicts.
C is not conflict serializable
T1 reads and writes ‘a’, but T2 also writes ‘a’ between T1s operations.

30
Q

Which of the following is correct?

a. Result of a SQL query by default comes without a duplicate
b. SQL permits attribute names to be repeated in the same table
c. SQL SELECT query doesn’t work without primary keys
d. None of the above

A

d. None of the above

31
Q

Which is a valid SQL command for comparing a value in an attribute?

a. SELECT * FROM employee WHERE age>50 and <60;
b. SELECT * FROM employee WHERE age>50 and age <60;
c. SELECT * FROM employee WHERE age>50 and WHERE age<60;
d. None of the above

A

b. SELECT * FROM employee WHERE age>50 and age <60;

32
Q

What specified is used to uniquely define records/rows in a table?

a. Primary Key
b. Foreign Key
c. Unique Key

A

a. Primary Key

33
Q

What links data between tables?

a. Primary Key
b. Foreign Key
c. Unique Key

A

b. Foreign Key

34
Q

If several concurrent transactions are executed over the same data set and the second transaction updates the
database before the first transaction is finished which property is violated?

a. Atomicity
b. Consistency
c. Durability
d. Isolation

A

d.Isolation

35
Q

The _________ lock allows concurrent read on data items.

a. Shared
b. Binary
c. Complete
d. Exclusive

A

a.Shared

36
Q

If the precedence graph has no cycles, then the schedule, S is

a. Conflict serialisable
b. Conflict equivalent
c. Serial
d. None of the above

A

a.Conflict serialisable

37
Q

Deadlocks are possible only when one of the transactions wants to obtain an __________ lock on a data item.

a. Exclusive
b. Binary
c. Complete
d. Shared

A

a. Exclusive

38
Q

Schema: Course(course_id, sec_id, semester)

Choose the correct statement inside each tuple.

Here the course_id, sec_id and semester are (Tuple, Relation, Attributes) and course is a (Tuple, Relation, Attributes).

A

Here the course_id, sec_id and semester are Attributes and course is a Relation

39
Q

An Employees entity set has subclasses HourlyEmployee and SalaryEmployee, where every Employee entity
necessarily have to be within either HourlyEmployee or SalaryEmployee.

The above statement is (False, True) and it is an example of (Participation
constraint, Covering constraint)

A

The above statement is True and it is an example of Covering constraint

40
Q

How many tuples do you get when you multiply one table with 6 rows by a table with 4 rows together?

A

24 tuples (6*4)

41
Q

Stored procedures can have which of the following parameters

a. IN, OUT, INOUT
b. GET, PUT, GETPUT
c. READ, WRITE, READWRITE
d. All of the above

A

a. IN, OUT, INOUT

42
Q

Given relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(cid: integer, cname: string, meets at: time, room: string, lid: integer)
Enrolled(snum: integrer, cid: integer)
Lecturer(lid: integer, lname: string, deptid: integer)

Write the SQL statements required to create these relations, including appropriate
versions of all primary and foreign key integrity constraints.

A
CREATE TABLE Students( snum INTEGER, 
       sname CHAR(20), 
       major CHAR(20), 
       level CHAR(20), 
       age INTEGER, 
       PRIMARY KEY (snum)) 
CREATE TABLE Class (cid INTEGER, 
         cname CHAR(20), 
              meets_at TIME, 
         room CHAR(20), 
              lid INTEGER, 
              PRIMARY KEY(cid), 
         FOREIGN KEY (lid) REFERENCES Lecturer ) 

CREATE TABLE Enrolled ( snum INTEGER,
cid INTEGER,
PRIMARY KEY (snum,cid),
FOREIGN KEY (snum) REFERENCES Student ,
FOREIGN KEY (cid) REFERENCES Class )

CREATE TABLE Lecturer ( lid INTEGER,
lname CHAR(20),
deptid INTEGER,
PRIMARY KEY (lid))

43
Q

Given relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(cid: integer, cname: string, meets at: time, room: string, lid: integer)
Enrolled(snum: integrer, cid: integer)
Lecturer(lid: integer, lname: string, deptid: integer)

Express the following integrity constraints in SQL.
1.  Every class has a minimum enrolment of 5 students and a maximum enrolment of 
30 students.
A
CREATE TABLE Enrolled ( snum INTEGER, 
       cid INTEGER, 
       PRIMARY KEY (snum,cid), 
FOREIGN KEY (snum) REFERENCES Student , 
       FOREIGN KEY (cid) REFERENCES Class , 
       CHECK (( SELECT COUNT(E.snum) 
FROM Enrolled E 
GROUP BY E.cid)>5), 
       CHECK (( SELECT COUNT(E.snum) 
FROM Enrolled E 
GROUP BY E.cid)<=30) )
44
Q

Given relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(cid: integer, cname: string, meets at: time, room: string, lid: integer)
Enrolled(snum: integrer, cid: integer)
Lecturer(lid: integer, lname: string, deptid: integer)

Express the following integrity constraints in SQL.
Every Lecturer must teach at least two courses.

A
CREATE ASSERTION Teach Two 
CHECK((SELECT COUNT(*) 
FROM Lecturer L, Class C 
WHERE L.lid = C.lid 
GROUP BY C.lid 
HAVING COUNT(*)<2) = 0)
45
Q

Given relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(cid: integer, cname: string, meets at: time, room: string, lid: integer)
Enrolled(snum: integrer, cid: integer)
Lecturer(lid: integer, lname: string, deptid: integer)

Express the following integrity constraints in SQL.
Only Lecturer in the department with deptid=33 should teach more than three courses.

A
CREATE ASSERTION No Teach Three 
CHECK((SELECT COUNT(*) 
FROM Lecturer L, Class C 
WHERE L.lid = C.lid AND L.deptit ≠ 33 
GROUP BY C.lid 
HAVING COUNT(*)>3) = 0)
46
Q

Given relations:

Student(snum: integer, sname: string, major: string, level: string, age: integer)
Class(cid: integer, cname: string, meets at: time, room: string, lid: integer)
Enrolled(snum: integrer, cid: integer)
Lecturer(lid: integer, lname: string, deptid: integer)

Express the following integrity constraints in SQL.
Two classes cannot meet in the same room at the same time.

A
CREATE TABLE Class ( cid INTEGER, 
cname CHAR(20), 
       meets_at TIME, 
       room CHAR(20), 
       lid INTEGER, 
       PRIMARY KEY(cid), 
       FOREIGN KEY (lid) REFERENCES Lecturer, 
       CHECK(( SELECT C.room,C.meets 
FROM Class C 
GROUP BY C.room,C.meets 
HAVING COUNT(*)>1))=0)
47
Q

Describe the concept of transactions? Hint: ACID

A

The concept of transactions can be described with four key properties: atomicity, consistency,
isolation, and durability (ACID).

• Atomicity: A transaction is an atomic operation that consists of a series of actions.
The atomicity of a transaction ensures that the actions either complete entirely or
take no effect at all.

• Consistency: Once all actions of a transaction have completed, the transaction is
committed. Then your data and resources will be in a consistent state that
conforms to business rules.

• Isolation: Because there may be many transactions processing with the same data
set at the same time, each transaction should be isolated from others to prevent
data corruption.

• Durability: Once a transaction has completed, its result should be durable to
survive any system failure (imagine if the power to your machine was cut right in
the middle of a transaction commit). Usually, the result of a transaction is
written to persistent storage

48
Q

What is the difference between a primary index and a secondary index?

What is a duplicate data entry in an index?

Can a primary index contain duplicates?

A

An index on a set of fields that includes the primary key is called a primary index; other indexes are
called secondary indexes. Two data entries are said to be duplicates if they have the same value for
the search key field associated with the index. A primary index is guaranteed not to contain
duplicates, but an index on other (collections of) fields can contain duplicates

49
Q

How is indexing used in DBMS?

A

Indexing is used to optimize the performance of a database by minimizing the number of disk accesses required when a query is processed.

50
Q

What is indexing in DBMS?

A

The index is a type of data structure. It is used to locate and access the data in a database table quickly

51
Q

What are some indexing methods?

A
  • Ordered indices
  • Primary Index
  • Secondary Index
  • Clustering Index
52
Q

What are the two sub-methods of primary index?

A

Dense Index and Sparse index

53
Q

Explain Ordered Indices

A

The indices are usually sorted to make searching faster. The indices which are sorted are known as ordered indices

54
Q

Explain Primary Index. What is its two sub-methods?

A

If the index is created on the basis of the primary key of the table, then it is known as primary indexing. These primary keys are unique to each record and contain 1:1 relation between the records.

As primary keys are stored in sorted order, the performance of the searching operation is quite efficient.

The primary index can be classified into two types: Dense index and Sparse index.

55
Q

What is dense index?

A

The dense index contains an index record for every search key value in the data file. It makes searching faster.

In this, the number of records in the index table is same as the number of records in the main table.

It needs more space to store index record itself. The index records have the search key and a pointer to the actual record on the disk.
56
Q

What is sparse index?

A

In the data file, index record appears only for a few items. Each item points to a block.

In this, instead of pointing to each record in the main table, the index points to the records in the main table in a gap.
57
Q

What is clustering index?

A

Get index out of two or more columns.

Example of this would be to create an index on a group of people, say, all the students in a particulal class.

58
Q

What is secondary index?

Can a secondary index produce duplicates?

A

A secondary index, put simply, is a way to efficiently access records in a database by means of some piece of information other than the usual (primary) key.

A Secondary index is an index that is not a primary index and may have duplicates. eg. Employee name can be example of it. Because Employee name can have similar values.

So yes, secondary indexes may have duplicates.

59
Q

Does weak entities in an ER diagram have a key attribute?

A

No, a weak entity does not have key attribute, but relies on its ‘‘parent’’ entity to provide the key attribute.

60
Q

Explain a multivalued attribute in an ER diagram and how is a multivalued attribute portrayed in an ER diagram?

A

An attribute can have more than one value. These attributes are known as a multivalued attribute. The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.

61
Q

How is a key attribute represented in an ER diagram?

A

The name inside the oval is underlined.

62
Q

Explain: Composite Attribute.

A

A composite attribute is an attribute that consists of other attributes.
The composite attribute is represented by an ellipse.

A composite attribute is an attribute of an attribute.

Examle is an attribute “NAME” which have the composite attributes “FIRST_NAME”, “LAST_NAME” and “MIDDLE_NAME”

63
Q

What is a derived attribute and how is it represented in an ER diagram?

A

An attribute that can be derived from other attribute is known as a derived attribute. It can be represented by a dashed ellipse.

For example, A person’s “age” changes over time and can be derived from another attribute like “Date_of_birth”.