Data Relationships Flashcards

1
Q

Types of Data Relationships

A

1: 1 one to one
1: M one to many

M:M many to many

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

1:1 one to one

A

one:one (1:1)

Single table rarely two tables PK & FK
relationships i.e

1 employee belongs to 1 organization

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

1:M one : many

A

1:M one to many

Two tables with PK & FK relationship
Parent/Children - Single order many items

Example: 1 person has many cars
1 company has many employees

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

M:M many to many

A

M:M many to many

Junction table keys from Both tables forming PK
Tricky to Represent
Examples: Student / Subject
1 Student has many Subjects
1 Subject has many Students
Employee/ Department

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

SQL Joins

A

Combines 2+ tables, based on a common field

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

Types of Joins

A
  1. Inner Join
  2. Left Join
  3. Right Join
  4. Outer Join
  5. Full Join
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Inner Join

A

Inner Join - All rows where at least 1 match in both tables.

From A Inner B A = B key. xx = shared data
x x
A x x B
x x

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

Left Join

A

Left Join - All rows from left table, match rows from right

Select From A Left join B on A key = B key where B key = null
Display A data that is not shared with B === data not shared
AABB
AAA====BBB

Select From A Left join B on A Key = B Key
Display all A data including data shared with B === data shared
AABB
AAA====BBB

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

Right Join

A

Right Join - All rows from Right table match from left

Select * From A Right Join B on A = B (retrieves all B data and shared A data)
Select * From A Right Join B on A = B Where A = NULL (retrieves B data that is not shared with A data)

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

Outer Join

A

Outer Join - Select From Table A Full Outer Join B
ON A.Key = B. Key
Where A.Key or B.Key = Null

The data shared between A and B is NOT selected

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

Full Join

A

Full Join - Select From A Full Outer Join B
Key A = Key B

Retrieves all data from both tables
UNION / UNION ALL

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

Intersection

A

2 tables list match records

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