Exam Flashcards

1
Q

RELATIONSHIP TABLES

in a 1 to many relationship what do we do with the entities and the relationship?

A

combine the the 1 with the relationship (i.e. the one with the arrow)

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

RELATIONSHIP TABLES

how are participation constraints manifested as in tables?

A

by not nulls

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

RELATIONSHIP TABLES

how are key/cardinality constraints manifested?

A

by foreign keys

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

RELATIONSHIP TABLES

how are binary relationships manifested?

A

their own table with a composite primary key that reflects the two different types of relationships they describe

EX. reports_to has supervisor/subordinate so the primary key is supervisor_ssn,subordinate_ssn which are foreign keys of the parent entity

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

RELATIONSHIP TABLES

how are weak entities displayed?

A

a weak entity combines the entity with the relationship it is defined by and then uses a partial key composed of its local key and the primary key of the connected entity(s) (also ON DELETE CASCADE/UPDATE)

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

RELATIONSHIP TABLES

if an entity has a participation constraint does it always require its own table?

A

not always

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

ER DIAGRAMS

“must participate”

A

this means a participation constraint or a thick line connecting the two elements

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

ER DIAGRAMS

“X is related to NO MORE than ONE Y”

A

key constraint - draw an arrow pointing to Y from X

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

ER DIAGRAMS

what is a cardinality constraint?

A

look for arrows and their can only be one of those elements in a relationship between them

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

ER DIAGRAMS

what is a participation constraint?

A

look for thick lines. entities connected must be paired as tuples at all times

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

ER DIAGRAMS

thick line

A

> 1

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

ER DIAGRAMS

arrow

A

< 1

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

FDs/NORMAL FORMS

define 3NF

A

where all FDs have either the superkey on the LHS OR their RHS is part of the superkey

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

FDs/NORMAL FORMS

How do we synthesize 3NF?

A

1) reduce to single attribute RHS
2) check LHS to see if every attribute is actually necessary for the FD
3) remove redundant rules (check closures to see/remove repeats)
4) take completed FDs and write out as R1(xy) R2(yz)…

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

FDs/NORMAL FORMS

define BCNF

A

where all FDs are strictly have the superkey on the LHS

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

FDs/NORMAL FORMS

how do we decompose to BCNF?

A

1) check which FDs are not in BCNF and decompose on the ones which are not
2) Decompose R into two subschemas, one with the offending FD attributes, the other with the original minus the offending
3) now check those subschemas as if they were their own relations, and iterate over and over until both satisfy BCNF

17
Q

RA/DATALOG

What is division used for?

A

“find all of that have RESERVED ALL BOATS” for example

18
Q

SQL

what does WHERE IN do?

A

It looks for the given attribute in the results of the subquery.

ex. “Find the who did X”

19
Q

SQL

WHERE EXISTS does what?

A

Checks whether a given set is empty or not

“Find the blank of blanks who have done x”

20
Q

SQL

ANY does what?

A

finds a random example of the subquery that follows it

21
Q

SQL

ALL does what?

A

finds every example of the subquery that follows it

22
Q

SQL

WHERE NOT EXISTS does what?

A

returns true if the subquery doesn’t satisfy the result

23
Q

SQL

COUNT ((DISTINCT) A) does what?

A

the number of values in column A

24
Q

SQL

GROUP BY

A

Collects the query results by the given attribute

25
Q

SQL

HAVING does what?

A

condition to satisfy for given query group

26
Q

DATALOG

How do you do joins?

A

atoms with specific named attributes

27
Q

Find the names of bookstores that have sold EVERY book which is old by the bookstore named chapters

A

use WHERE NOT EXISTS looking for all ids from the sold table where the name is chapters. EXCEPT those where the sold name is the same as the bookstore name.

28
Q

Find the names of the bookstores that have sold at least 100 different books published after year 2000

A

do a join of Sold and Book and check the year in the WHERE clause. use GROUP BY name and HAVING count (distinct id) >= 100

29
Q

if you see a not atom in datalog how is it written in SQL

A

WHERE NOT EXISTS clause

30
Q

Find the names of sailors with a higher rating that ALL sailors with age < 21

A

use WHERE NOT EXISTS subquery where the subquery’s age is less than 21 and S.rating <= S2. rating

31
Q

Find the title and year of those albums that are sold in every store in Toronto

A

use WHERE NOT EXISTS where you select the stores where city is toronto EXCEPT the the sold albums that share ids with the original query

the first inner query should be WHERE NOT EXISTS and get the store ids of all stores in toroonto. the bottom inner query (the EXCEPT) should get the store ids where the album was sold and this is connected ot the initial query by S.aid=A.aid. if this set difference is empty, then every store in toronto had the album.

32
Q

Find the names of all juniors who are enrolled in a class taught by I. Teach

A

just a WHERE clause with the appropriate joins and selections

33
Q

Find the age of the oldest student who is either a History major or enrolled in a course taught by I. Teach.

A

SELECT MAX(S.age) and a normal WHERE clause for history and then and OR statement with a subquery that is close to the previous question

34
Q

Find the names of all classes that either meet in room R128 or have 5+ students enrolled

A

simple WHERE ORd with IN subquery. subquery GROUPSBY name with a HAVING clause of 5 or more)

35
Q

Find the names of faculty members who teach in every room in which some class is taught

A

You know to use WHERE NOT EXISTS to find all classes and then an except clause to find the classes in whcih the faculty members teach