Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,490 --> 00:00:03,320
In this lesson, we're
going to be looking
2
00:00:03,320 --> 00:00:06,020
at really the
foundational pieces
3
00:00:06,020 --> 00:00:08,340
of the relational
database model.
4
00:00:08,340 --> 00:00:10,870
And that is the
relational table.
5
00:00:10,870 --> 00:00:14,210
Now, a table is built
to hold relational data
6
00:00:14,210 --> 00:00:17,750
and allow it to be
related to other tables
7
00:00:17,750 --> 00:00:21,380
in the form of
constraints and joins.
8
00:00:21,380 --> 00:00:25,050
Tables are composed
of rows and columns.
9
00:00:25,050 --> 00:00:27,680
So a row is going to be
an individual instance
10
00:00:27,680 --> 00:00:30,860
of information, something
like a customer record,
11
00:00:30,860 --> 00:00:34,160
whereas a column is going
to be an individual type
12
00:00:34,160 --> 00:00:39,530
of information-- so a first name
or a last name or a zip code.
13
00:00:39,530 --> 00:00:41,840
And the tables we're
referring to in this lesson
14
00:00:41,840 --> 00:00:45,020
are known as a heap
organized tables.
15
00:00:45,020 --> 00:00:46,880
They can be distinguished
from a couple
16
00:00:46,880 --> 00:00:48,750
of other types of tables.
17
00:00:48,750 --> 00:00:51,020
But they're called heap
organized because they
18
00:00:51,020 --> 00:00:52,940
store data basically in a heap.
19
00:00:52,940 --> 00:00:55,820
That is to say, as
the data comes in,
20
00:00:55,820 --> 00:00:58,250
that's how it's
stored in a table.
21
00:00:58,250 --> 00:01:02,000
When we create a table, we
have to declare data types
22
00:01:02,000 --> 00:01:03,350
for each of the columns.
23
00:01:03,350 --> 00:01:07,080
So we said that a column was
an individual type of data.
24
00:01:07,080 --> 00:01:10,540
So a first name will
always have character data.
25
00:01:10,540 --> 00:01:13,400
A date will always
have date data.
26
00:01:13,400 --> 00:01:15,980
And a number will always
have numeric data.
27
00:01:15,980 --> 00:01:19,610
So when we define the
columns for our tables,
28
00:01:19,610 --> 00:01:21,050
we use a data type.
29
00:01:21,050 --> 00:01:22,980
And the data types that
we're going to look at
30
00:01:22,980 --> 00:01:24,730
are kind of the basic
ones, although there
31
00:01:24,730 --> 00:01:31,810
are many other types, are CHAR,
VARCHAR2, NUMBER, and DATE.
32
00:01:31,810 --> 00:01:36,130
So CHAR is a
character-based data type
33
00:01:36,130 --> 00:01:37,750
that holds character data.
34
00:01:37,750 --> 00:01:42,760
When we define a CHAR data
type, we use a max number
35
00:01:42,760 --> 00:01:45,790
of characters that we
specify the CHAR---
36
00:01:45,790 --> 00:01:50,350
C-H-A-R-- and then in
parentheses a digit for the max
37
00:01:50,350 --> 00:01:51,730
number of characters.
38
00:01:51,730 --> 00:01:55,210
So if we had a
CHAR(5), we have a five
39
00:01:55,210 --> 00:01:59,420
digit fixed-width character that
can hold those five characters.
40
00:01:59,420 --> 00:02:02,590
So it basically allocates
five characters.
41
00:02:02,590 --> 00:02:06,130
So if we have the word
hello in a CHAR(5),
42
00:02:06,130 --> 00:02:08,830
we see that it fills
all of the five spaces
43
00:02:08,830 --> 00:02:10,990
that are given to
it for a maximum.
44
00:02:10,990 --> 00:02:15,280
If we were to use a state
code like NY in a CHAR(5),
45
00:02:15,280 --> 00:02:19,990
these extra spaces would
actually be essentially wasted
46
00:02:19,990 --> 00:02:22,360
because CHAR(5) will
allocate those out
47
00:02:22,360 --> 00:02:25,150
for the purposes of storage
but will not actually
48
00:02:25,150 --> 00:02:27,220
store anything in them.
49
00:02:27,220 --> 00:02:29,080
So with CHAR, we
make the distinction
50
00:02:29,080 --> 00:02:31,810
of a fixed-width data type.
51
00:02:31,810 --> 00:02:35,530
CHAR is a data type that
Oracle does not recommend
52
00:02:35,530 --> 00:02:38,290
that users use any longer--
53
00:02:38,290 --> 00:02:42,280
that is to say, to not
create tables with CHAR.
54
00:02:42,280 --> 00:02:45,430
It is still allowed
and still works
55
00:02:45,430 --> 00:02:47,780
within the Oracle 12c database.
56
00:02:47,780 --> 00:02:51,070
However, a number of
features that they have
57
00:02:51,070 --> 00:02:52,460
can have problems with it.
58
00:02:52,460 --> 00:02:56,740
So there can be bugs associated
with using the CHAR data type.
59
00:02:56,740 --> 00:03:00,520
Essentially, they no longer
test using CHAR data.
60
00:03:00,520 --> 00:03:06,220
So it's best to go to our next
data type, which is VARCHAR2.
61
00:03:06,220 --> 00:03:09,250
So VARCAR2 is defined
in the same way,
62
00:03:09,250 --> 00:03:13,400
where x in the parentheses is
the max number of characters.
63
00:03:13,400 --> 00:03:18,440
However, VARCHAR2 2 is a 5
digit variable-width data type.
64
00:03:18,440 --> 00:03:23,560
So if we have the word hello
in a VARCHAR2(5), that's
65
00:03:23,560 --> 00:03:27,370
how we would say it, all of
those spaces would be used.
66
00:03:27,370 --> 00:03:32,290
However, if we used the state
code like NY in a VARCHAR2(5),
67
00:03:32,290 --> 00:03:35,660
those extra spaces
would not be allocated.
68
00:03:35,660 --> 00:03:37,810
So there's essentially
a little bit of savings
69
00:03:37,810 --> 00:03:42,610
there in terms of storage when
we use a variable-width data
70
00:03:42,610 --> 00:03:44,960
type.
71
00:03:44,960 --> 00:03:48,640
The NUMBER data type is defined
by two variables, if you will,
72
00:03:48,640 --> 00:03:50,970
that we define for it--
73
00:03:50,970 --> 00:03:52,800
p, s.
74
00:03:52,800 --> 00:03:55,650
p is precision and s is scale.
75
00:03:55,650 --> 00:04:01,020
Precision will be the max
number of digits in the number.
76
00:04:01,020 --> 00:04:02,970
Scale will be the
number of digits
77
00:04:02,970 --> 00:04:05,680
to the right of
the decimal place.
78
00:04:05,680 --> 00:04:10,290
So example, we could
have a NUMBER(5,2).
79
00:04:10,290 --> 00:04:13,140
And this number
would be acceptable.
80
00:04:13,140 --> 00:04:16,750
This number would be acceptable,
even though it's only four
81
00:04:16,750 --> 00:04:18,120
for the precision.
82
00:04:18,120 --> 00:04:22,360
Basically four characters fits
within the five precision.
83
00:04:22,360 --> 00:04:23,830
And this as well.
84
00:04:23,830 --> 00:04:26,710
But this number would not
because even though it
85
00:04:26,710 --> 00:04:31,510
is five digits, essentially
the scale that we define, a 2,
86
00:04:31,510 --> 00:04:34,910
allows for two digits
after the decimal point.
87
00:04:34,910 --> 00:04:39,050
And so if this number was to
be updated, say that column,
88
00:04:39,050 --> 00:04:41,350
and we had two
digits to the right,
89
00:04:41,350 --> 00:04:45,050
we would then have too many
digits, causing an error.
90
00:04:45,050 --> 00:04:48,600
So this number would
not be allowed.
91
00:04:48,600 --> 00:04:52,830
The DATE data type is simply
data containing date and time
92
00:04:52,830 --> 00:04:54,150
information.
93
00:04:54,150 --> 00:04:58,110
And this can be
extracted using the 2CHAR
94
00:04:58,110 --> 00:05:02,010
function when we want to see
the specifics of date and time.
95
00:05:02,010 --> 00:05:05,850
By default, Oracle has
a standard date format
96
00:05:05,850 --> 00:05:11,390
that it shows whenever we
select data from a date column.
97
00:05:11,390 --> 00:05:14,390
There are certain rules
about tables and columns
98
00:05:14,390 --> 00:05:15,920
concerning their naming.
99
00:05:15,920 --> 00:05:17,690
So it's important
to understand those
100
00:05:17,690 --> 00:05:21,230
so we know what goes
into the choosing
101
00:05:21,230 --> 00:05:23,900
a name for a column and a table.
102
00:05:23,900 --> 00:05:25,640
So table and column
names need to be
103
00:05:25,640 --> 00:05:28,130
between 1 and 30 characters--
104
00:05:28,130 --> 00:05:30,380
no more than 30 characters.
105
00:05:30,380 --> 00:05:32,480
For the digits in
the names, we only
106
00:05:32,480 --> 00:05:37,100
allow alphanumeric values and
the hash sign, the underscore,
107
00:05:37,100 --> 00:05:38,680
and the dollar sign.
108
00:05:38,680 --> 00:05:42,560
A table must begin with
a letter between A and Z.
109
00:05:42,560 --> 00:05:45,140
And it's not case
specific, in this case.
110
00:05:45,140 --> 00:05:47,690
It could be lowercase
or uppercase.
111
00:05:47,690 --> 00:05:51,590
Reserved words can't be used
as table or column names.
112
00:05:51,590 --> 00:05:57,200
So a name like select for a
table would not be allowable.
113
00:05:57,200 --> 00:06:00,260
However, most of these
rules can be overridden
114
00:06:00,260 --> 00:06:02,750
using the double quotes.
115
00:06:02,750 --> 00:06:05,720
So if we use double quotes
around a table or a column
116
00:06:05,720 --> 00:06:08,480
name, we can break
some of these rules.
117
00:06:08,480 --> 00:06:11,570
However, I would highly
advise against it.
118
00:06:11,570 --> 00:06:13,640
Because when a
database administrator
119
00:06:13,640 --> 00:06:17,990
looks in the data dictionary for
a table or a particular column,
120
00:06:17,990 --> 00:06:19,760
they're looking
with the expectation
121
00:06:19,760 --> 00:06:23,190
that they're going to find
that in all uppercase.
122
00:06:23,190 --> 00:06:27,200
So if we create a table in lower
case using the SQL statement
123
00:06:27,200 --> 00:06:31,290
CREATE TABLE, Oracle will
store the name as uppercase.
124
00:06:31,290 --> 00:06:33,230
But when we use
the double quotes,
125
00:06:33,230 --> 00:06:36,860
that forces Oracle to store
it exactly as it was defined.
126
00:06:36,860 --> 00:06:40,670
And so we may be looking for a
table with uppercase letters.
127
00:06:40,670 --> 00:06:43,640
And actually they've been
stored as lowercase letters
128
00:06:43,640 --> 00:06:47,770
because someone has created
them using the double quotes.
129
00:06:47,770 --> 00:06:50,290
So the format of the
CREATE TABLE syntax
130
00:06:50,290 --> 00:06:55,180
is going to be CREATE TABLE and
the table name, a parentheses,
131
00:06:55,180 --> 00:06:58,120
and then column,
data type, column,
132
00:06:58,120 --> 00:07:03,830
data type, and so on, then a end
parentheses, and a semicolon.
133
00:07:03,830 --> 00:07:08,770
So let's connect to our system
user and create a simple table.
134
00:07:18,970 --> 00:07:21,590
We have a column1
of CHAR(5) five.
135
00:07:21,590 --> 00:07:24,140
Column2, that's data
type VARCAR2(5).
136
00:07:27,410 --> 00:07:30,570
Column3 will be a NUMBER(5,2).
137
00:07:33,580 --> 00:07:35,460
Column4 will be a DATE.
138
00:07:38,270 --> 00:07:42,430
Execute the statement,
table was created.
139
00:07:42,430 --> 00:07:46,970
Now, if we do a select
star from test table,
140
00:07:46,970 --> 00:07:49,590
we'll see those columns defined.
11532
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.