mode 5 SQL III Flashcards

1
Q

What is multiplicity?

A

Multiplicity describes the relationship between tables/entities.

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

Types of multiplicity?

A

> MANY-TO-MANY
>owners to cars
>customers to stores
>fridges to healthinspectors

> MANY-TO-ONE
>workers to managers
>carModels to carMake
>fridges to restaurant

> ONE-TO-MANY
>managers to workers
>carMake to carModels
>restaurant to fridges

> ONE-TO-ONE
>currentGovener to state
>person to drivers license
>person to ssn

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

What is referential integrity?

A

The enforcing of foreign keys referencing valid and existing primary keys

Essentially, referential integrity protects us from having orphan records

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

What is an orphan record?

A

Because a record w/ a FK references a PK record, the record w/ a FK is DEPENDENT upon the PK record…
meaning the PK record is a parent record to the FK record (aka the child record)

So…if you delete the Parent record then the child record (FK) will no longer have a parent, it will be referred to as an orphan record. REFERENTIAL INTEGRITY protects us from accidentally creating any orphan records.

To delete the parent record, you must first delete the children records (also, you can look into “cascade on delete” OR you could set the child’s FK field to null temporarily)

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

What is a join?

A

It’s a way to combine two or more tables into a single result set based on some attributes (like a FK)

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

Types of Joins?

A

> Inner Join
Outer Join
>Left
>Right
>Full
Cartesean Join / Cross Join
(example: shirt size table cartesean join shirt graphics table)
Self Join: (when a table joins with itself)
(example: employee and managers that are also employees. so a reports_to attribute)
(example: person join person ON PPK=spouse_id)
Equijoin: (equijoins are when we use equalities “=”)
(example employee joins otherTable ON EPK = reports_to)
Thetajoin: (theta joins are when we use inequalities like >, Natural Join
N-way join
etc

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

What are set operators

A

set operators combine result sets into a single NEW result set

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

Types of Set Operators

A

Union: takes all the data entries in both result sets and puts them into a NEW result set, no duplicates

Union All: takes all the data entries in both result sets and puts them into a NEW result set, yes duplicates

Intersect: takes all the data entries that happen to appear in BOTH result sets and puts them into a NEW result set

Minus: takes all the data entries from the left result set and subtracts any data entries that happen to appear in the right table

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

Sample syntax for set operators

A

EXAMPLE SYNTAX
SELECT * FROM tableA WHRE attr1=’stuff’ AND attr3=10;
UNION
SELECT * FROM tableB WHRE attr2=5;

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

What are the requirements for set operators?

A

Requirements for the set operators:

  • each result set must have the same number of columns AND
  • each column must have the same datatypes [and order of the datatypes].
  • The names of the columns don’t matter, they don’t have to match
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is normalization?

A

Normalization is the process of organizing your DB schema to reduce data redundancy and DB inconsistencies

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

Types of Normalization

A

1st Normal Form (1st NF)

  • Each record must have a PK, relevant to the table
  • Attributes should be atomic/granular
    • –break down attributes into their smallest possible units
    • –no “name” column, you’d do “firstname” and “lastname” columns
  • Attributes must be singular
    • –no “cust1”, “cust2”, “cust3”…they should be in their own table, then have a multiplicity relationship

> > > > > > > 2nd Normal Form (2nd NF)

  • Must be in 1st NF
  • All attributes MUST be dependant on the PK
    • –to put it another way, attributes in the table should be properties of THIS record
  • No parital dependencies
    • –this deals with composite keys
    • –example (Author, BookTitle) “Author Age”

> > > > > > > > > 3rd Normal Form (3rd NF)

  • Must be in 2nd NF
  • No transitive dependencies
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a lookup table?

A

A lookup table is normally a table that acts as a “master list” for something and you use it to look up a business key value (like “Make”) in exachange for it’s identifier (like the id column) for use in some other table’s foreign key column.

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

What is enum?

A

Enumeration

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

What is a View?

A

A view is essentially a projection of 1 or more ACTUAL tables.

The view itself is just a virtual table, it doesn’t store data, it just references data from other tables.
In other words, a view stores a query so you can access massive queries easier

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

What is a materialized view?

A

It’s a view that DOES store data

17
Q

What is an index?

A

You can create indexes on a table to speed up searching on a table. It becomes useful when you’re looking in a small range of a table that has a LOT of records.

It’s similiar to a table of contents.