Relational Data Model Flashcards

1
Q

What is a relational database?

A

A set of relations

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

What are the two parts of a relation?

A

Instance (table) and Scheme (name, plus attributes)

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

What is the cardinality of a relation?

A

Number of Rows

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

What is the degree of a relation?

A

Number of columns

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

What is the DDL used for?

A

Creation, Deletion, Updating, Truncate, Rename relation

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

What is the simple form of creating a relation?

A

CREATE TABLE ( ssn INTEGER );

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

What are the 4 most common data types?

A

INT, REAL, CHAR(n), VARCHAR(n)

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

What is the form of the data value?

A

yyyy-mm-dd

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

What is the form of the time value?

A

hh:mm:ss.ss

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

What is the syntax to delete a relation?

A

DROP TABLE ;

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

How do you add any existing attribute to a relation scheme

A

ALTER TABLE ADD

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

How do you remove an attribute from a relation?

A

ALTER TABLE DROP

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

How do you insert a single tuple?

A

INSERT INTO Students(sid, name) VALUES (53, ‘Smith’)

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

Do you delete all tuples satisfying some condition?

A

DELETE
FROM Students S
WHERE S.name = ‘Smith’

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

What are integrity constraints?

A

Conditions that must be true for any instance of the database

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

When are ICs specified?

A

When schemes are defined

17
Q

When are ICS checked?

A

When relations are modified?

18
Q

How are keys declared?

A

Using the PRIMARY KEY or UNIQUE keywords after a single attribute or after all attributes using PRIMARY KEY(attr1, attr2)

19
Q

What’s the difference between PRIMARY KEY and UNIQUE?

A

Exactly 1 PK, but 0+ UNIQUE

NULLS not allowed in PK, but UNIQUE can have NULLs

20
Q

How do you force a value to exist and enforce total participation?

21
Q

What is a foreign key?

A

A set of fields in one relation that is used to refer to a tuple in another relation

22
Q

How do you specify FOREIGN KEY?

A

FOREIGN KEY (sid) REFERENCES STudents

23
Q

What are the options for foreign key violations?

A

NO ACTION, CASCADE, SET NULL, SET DEFAULT
Ex ON DELETE CASCADE
ON UPDATE SET DEFAULT

24
Q

How to convert an entity to a relation?

A

CREATE TABLE ( PRIMARY KEY );

25
How to convert a relationship to a relation?
Attributes must include the keys of each entity and any additional descriptive attributes. Add foreign key for the keys of the entities
26
How to convert Many to One relationships to relations?
Combine both entities into the "many"; Ex: Given many drinkers and 1 favorite beer: Drinkers(name, addr, favBeer)
27
Can we combine many-many relationships?
No, creates much redundancy
28
How to convert a weak entity set to relations?
Combine the relationship and weak entity into one relation, adding the foreign key of the supporting entity as a relationship
29
How do enforce total participation?
use NOT NULL (especially on foreign keys)
30
What are the 3 approaches to subclasses?
1. Object Oriented: one relation per subset of subclasses with all relevant attributes 2. Use nulls: one relation, use NULLs in attributes that don't belong 3. E/R: one relation for each subclass (key attributes, attributes of that subclass)
31
What is a view?
A relation that stores a definition, rather than a set of tuples. Used to present necessary information while hiding details of the underlying relations (security)