Relational schemas - Primary key.pdf

32 views 135 slides Aug 07, 2023
Slide 1
Slide 1 of 135
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89
Slide 90
90
Slide 91
91
Slide 92
92
Slide 93
93
Slide 94
94
Slide 95
95
Slide 96
96
Slide 97
97
Slide 98
98
Slide 99
99
Slide 100
100
Slide 101
101
Slide 102
102
Slide 103
103
Slide 104
104
Slide 105
105
Slide 106
106
Slide 107
107
Slide 108
108
Slide 109
109
Slide 110
110
Slide 111
111
Slide 112
112
Slide 113
113
Slide 114
114
Slide 115
115
Slide 116
116
Slide 117
117
Slide 118
118
Slide 119
119
Slide 120
120
Slide 121
121
Slide 122
122
Slide 123
123
Slide 124
124
Slide 125
125
Slide 126
126
Slide 127
127
Slide 128
128
Slide 129
129
Slide 130
130
Slide 131
131
Slide 132
132
Slide 133
133
Slide 134
134
Slide 135
135

About This Presentation

Relational schemas - Primary key


Slide Content

Basic Database Terminology

Relational Schemas: Primary Key

Relational Schemas: Primary Key

Relational Schemas: Primary Key

Relational Schemas: Primary Key

Relational Schemas: Primary Key

Relational Schemas: Primary Key
these tables have a tabular shape

Relational Schemas: Primary Key
these tables have a tabular form
a relational schema can be applied to represent them

Relational Schemas: Primary Key

Relational Schemas: Primary Key
sales per customer of our company

Relational Schemas: Primary Key

Relational Schemas: Primary Key
the dates of a few purchases may coincide

Relational Schemas: Primary Key
the ID of a customer may appear a few times

Relational Schemas: Primary Key
there is a possibility to see the same item code a few times

Relational Schemas: Primary Key

Relational Schemas: Primary Key
all the numbers in this column will be different

Relational Schemas: Primary Key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
primary key

Relational Schemas: Primary Key
Primary Key

Relational Schemas: Primary Key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key

Relational Schemas: Primary Key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-each table can have one and only one primary key

Relational Schemas: Primary Key
-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-in one table, you cannot have 3 or 4 primary keys

Relational Schemas: Primary Key
-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-in one table, you cannot have 3 or 4 primary keys

Relational Schemas: Primary Key
Primary Key
may be composed of a set of columns

Relational Schemas: Primary Key
Primary Key
may be composed of a set of columns
e.g. “purchase_number” + “date_of_purchase”

Relational Schemas: Primary Key
Primary Key
may be composed of a set of columns
e.g. “purchase_number” + “date_of_purchase”

Relational Schemas: Primary Key
Primary Key
one-column primary key = all purchases will be recorded under a
different number

Relational Schemas: Primary Key
-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-in one table, you cannot have 3 or 4 primary keys

Relational Schemas: Primary Key
-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-primary keys are the unique identifiers of a table
-in one table, you cannot have 3 or 4 primary keys

Relational Schemas: Primary Key
-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-primary keys are the unique identifiers of a table
-cannot contain null values!
-in one table, you cannot have 3 or 4 primary keys

Relational Schemas: Primary Key
Primary Key

Relational Schemas: Primary Key
Primary Key

Relational Schemas: Primary Key

Relational Schemas: Primary Key

Table name: Sales
Primary key: purchase_number
Other fields: date_of_purchase, customer_id, item_code
Relational Schemas: Primary Key

=
Relational Schemas: Primary Key

-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-primary keys are the unique identifiers of a table
-cannot contain null values!
Relational Schemas: Primary Key
-in one table, you cannot have 3 or 4 primary keys

-each table can have one and only one primary key
a column (or a set of columns) whose value exists and is unique for
every record in a table is called a primary key
Primary Key
-primary keys are the unique identifiers of a table
-cannot contain null values!
-not all tables you work with will have a primary key
Relational Schemas: Primary Key
-in one table, you cannot have 3 or 4 primary keys

relational schema
Relational Schemas: Primary Key

database schema
Relational Schemas: Primary Key

database schema
(relational schemas)
Relational Schemas: Primary Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key
always look for the foreign keys, as
they show us where the relations are

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key
no repeating and missing values

Relational Schemas: Foreign Key
no repeating and missing values
(unique values only)

Relational Schemas: Foreign Key
no repeating and missing values
repeating and missing values
(unique values only)

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key
ERROR

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key
no repeating and missing values

Relational Schemas: Foreign Key
no repeating and missing values
repeating and missing values

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key

Relational Schemas: Foreign Key
identifies the relationships between tables, not the tables themselves
foreign key

Relational Schemas: Foreign Key

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values
?

Relational Schemas: Unique Key & Null Values

You can have two or more
companies with the same name
Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values

You cannothave two US numbers that are completely identical
Relational Schemas: Unique Key & Null Values

?
Relational Schemas: Unique Key & Null Values

used whenever you would like to specify that you don’t want to see
duplicate data in a given field
unique key
Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values
unique keyprimary key
NULL VALUES no yes

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values
ERROR

Relational Schemas: Unique Key & Null Values
unique keyprimary key
NULL VALUES no yes
NUMBER OF KEYS 1 0, 1, 2…

Relational Schemas: Unique Key & Null Values
unique keyprimary key
NULL VALUES no yes
NUMBER OF KEYS 1 0, 1, 2…
APPLICATION TO
MULTIPLE COLUMNS
yes yes

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values

Relational Schemas: Unique Key & Null Values

Relationships

Relationships
Relationships

Relationships
Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa

Relationships

Relationships

unique values
Relationships

unique values
Relationships

unique values
repeated values
Relationships

unique values
repeated values
onevalue from the customer_idcolumn under the “Customers” table can
be found manytimes in the customer_idcolumn in the “Sales” table.
one-to-many type of relationship
Relationships

Relationships

Relationships

Relationships

1 customer
Relationships

1 customer1 purchase
Relationships

1 customer1 purchase
or >1 purchase
Relationships

1 customer1 purchase
or >1 purchase
Relationships

1 customer1 purchase
or >1 purchase
minimum # of instances of the
“Customers” table that can be
associated with the “Sales” entity
Relationships

1 customer1 purchase
or >1 purchase
1
minimum # of instances of the
“Customers” table that can be
associated with the “Sales” entity
Relationships

1 customer1 purchase
or >1 purchase
Relationships

1 customer1 purchase
or >1 purchase
maximum # of instances of the
“Customers” table that can be
associated with the “Sales” entity
Relationships

1 customer1 purchase
or >1 purchase
maximum # of instances of the
“Customers” table that can be
associated with the “Sales” entity
many
Relationships

Relationships

Relationships

1 purchase
Relationships

1 customer1 purchase
Relationships

1 customer1 purchase minimum =
Relationships

1 customer1 purchase minimum = = maximum
Relationships

1 customer1 purchase minimum = = maximum
Relationships

1 customer1 purchase minimum = = maximum
Relationships

Relationships

Relationships

Customers to Sales:one-to-many
Relationships

Customers to Sales:one-to-many
Relationships

Customers to Sales:one-to-many
Sales to Customers:many-to-one
Relationships

Relationships

cardinality constraints
Relationships

cardinality constraints
MN
Relationships

Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa
Relationships

Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa
types of relationships
Relationships

Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa
types of relationships
-one-to-many (many-to-one)
Relationships

Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa
types of relationships
-one-to-many (many-to-one)
-one-to-one
Relationships

Relationships
relationships tell you how much of the data from a foreign key field can
be seen in the primary key column of the table the data is related to
and vice versa
types of relationships
-one-to-many (many-to-one)
-one-to-one
-many-to-many
Relationships

Relational schemas
Relationships

Relational schemas
-represent the concept database administrators must implement
Relationships

Relational schemas
-represent the concept database administrators must implement
-depict how a database is organized
Relationships

Relational schemas
-represent the concept database administrators must implement
-depict how a database is organized
= blueprints, or a plan for a database
Relationships

Relational schemas
-represent the concept database administrators must implement
-depict how a database is organized
= blueprints, or a plan for a database
-will help you immensely while writing your queries!
Relationships