Week 4 Flashcards

1
Q

Normalization

A
  • goal is to avoid unneccessary data duplication
  • decomposing relations to well organized relations
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does not normalized data look like?

What does normalized data look like?

A
  • LOTS of duplication (Think tons of repeat supplier names for every product)

-make to 3 smaller tables and have no repeats! keep relationships to other tables through foreign keys

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

What is a well-structured relation

A
  • no data redundancy, allowing users to insert/delete/update rows w/o inconsistencies

GOAL: AVOID ANOMALIES

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

What are the types of anomalies that can arise

A

Insertion: adding new rows forces user to create duplicated data

Deletion: deleting rows may cause a loss of data that may be needed for future rows

Modification: changing data forces changes to other rows because of duplication

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

Rule of thumb about well structured relations

A

TABLE SHOULD NOT HAVE >1 ENTITY TYPE

(HAVE a lot of foreign keys but one entity type only)

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

Steps in normalization

A
  1. first normal form: no multi value attributes (a divided cell!) so all columns should only have one value (Remove partial dependencies)
  2. second normal form: within a single table, no 2 entities should have many to many relatinshiom (remove transitive dependencies)
  3. Third normal form: remove any other one to many relationships
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how do you know something is in a relationship database?

A

PKs and FKs

Can be searched with SQL queries

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

what is a relation?

A

two dimensional table of data! not a relationship!!

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

requirements for a relation

A
  • unqniue name
  • every att must be singular! no mv
  • every row must be unique
  • columns must be uniqe
  • order of rows and columsn not relevant
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

can keys be simle or composite

A

yes both!h

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

what is the point of indexes?

A

indexing!! keys do this!

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

Constraints: 3 types

A

domain- what are the allowable values for an attribute

entity integrity- PK must be not null and unique

referential integrity- MOST IMPORTANT! consistency!!! if you use FK it must exist

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

3 approaches to ensure referential integrity

A

restrict: restricting from deleting by cnnecting to FK

cascade: when you delete a parent row litl the relevant dependant cell will also be deleted

set to null: sets dependant cells to null

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

how to create referential integrity constriants??????? in sql

A

just link the FK’s!!!!

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

how to map entities to relaitons/tables

A

simple attribute (no mv!): each becames its own column

composite attributes: use only their simple, ocmponent attributes; each mv becomes onw column

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

How to handle foreign keys/primary key?

A
  1. Create the foreign key on the many side!!!
  2. ASSOCIATIVE ENTITIES: make everything have a primary key!! even associative entities (itll either be unique or combo of 2 fks)
17
Q

how to handle weak entities in creating an ERD in SQL?

A

2 WAYS FOR WEAK ENTITIES TO HAVE PK:

a) partial identifier + parent identifier

  1. weak entity needs to have the ID of its identifying parent entity
  2. set both the partial identifier and the ID of the identifying relationship as Primary keys!

b) surrogate identifier

18
Q

how to handle a ternary relationship?

A

Create 3+ FKS in the singular entity that has many pointing to it!

19
Q

WHERE DO YOU ADD A FOREIGN KEY?

A

ON THE MANY SIDE!!! OF THE CARIDNATILITY

20
Q

How to handle composite attributes?

A

break into separate rows in the entity table

21
Q

why do we call it a relation

A

mathematics!

22
Q

Relational schema:

How to read it?

A
  1. Each row is an entity, and each cell is an attribute
  2. solid underline is the PK
  3. Dashed line is the FK
  4. Relational arrow? this means a constraint! every time you delete an arrow it checks if you are violating a referential constraint
23
Q

How to handle composite attributes in entity relationship diagrams?

Company address (city, psotal code)

A

you make each composite attribute its own attribute (each has its own “column” which become a row in the entity)

24
Q

How to handle multivalue attributes
{Skills} in entity relationship diagram?

A
25
Q

Where do you add the foreign key?

A

on the many side or the optional side!!! BECAUSE otherwise youll have a column of just blanks on the other table :)

26
Q

How to model the attributes of a relationship in a relational database? (like the box coming off with a dashed line)

A

As an attribute of the entity with the foreign key on it

27
Q

How to model many to many relationship?

A

With a table in between! And then two foreign keys in it

If no indicaiton of unique primary key, then a combination of the two FK’s is a composite primary key

27
Q

How to deal with weak entities?

A

just as regular, but there are several potentially partial identiifier and also mark the strong entity ID as an attribute of the weak entity!!

DONT MARK THE STRONG ENTITY IDENTIFIER AS AN FK!!!

27
Q
A
27
Q
A
28
Q
A
29
Q
A