Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:01,510 --> 00:00:03,260
In this lesson, we're
going to take a look
2
00:00:03,260 --> 00:00:07,190
at the topic of concurrency
and what it means
3
00:00:07,190 --> 00:00:09,830
to transactions in a database.
4
00:00:09,830 --> 00:00:13,580
So any relational database
has to obey certain rules.
5
00:00:13,580 --> 00:00:17,450
And those rules are really to
keep the data consistent so
6
00:00:17,450 --> 00:00:20,840
that the view of the
data that one user has
7
00:00:20,840 --> 00:00:26,290
is consistent with what's been
committed by another user.
8
00:00:26,290 --> 00:00:30,250
So let's open up our database
connection, our tables,
9
00:00:30,250 --> 00:00:33,400
and the bonus table.
10
00:00:33,400 --> 00:00:35,130
I'm also going to
open up a command
11
00:00:35,130 --> 00:00:38,810
prompt here for the moment.
12
00:00:38,810 --> 00:00:44,070
And let's take a look
at the bonus table.
13
00:00:44,070 --> 00:00:47,490
So when we make a change
using DML language
14
00:00:47,490 --> 00:00:51,240
in the database, that being an
insert, an update, or a delete,
15
00:00:51,240 --> 00:00:54,570
those changes are not
considered real or permanent
16
00:00:54,570 --> 00:00:56,860
until a commit occurs.
17
00:00:56,860 --> 00:01:08,630
So let's do an example
here and insert.
18
00:01:08,630 --> 00:01:11,420
So if we select
from the table now,
19
00:01:11,420 --> 00:01:15,600
we see that row
inserted into the table.
20
00:01:15,600 --> 00:01:18,170
But what does another user see?
21
00:01:18,170 --> 00:01:20,090
So I'm going to connect
with a different tool.
22
00:01:20,090 --> 00:01:21,970
We could also do this
with a different window
23
00:01:21,970 --> 00:01:24,560
in SQL Developer.
24
00:01:24,560 --> 00:01:28,930
I'm going to connect to the
database using SQL*Plus.
25
00:01:28,930 --> 00:01:34,400
And I will select
star from bonus.
26
00:01:34,400 --> 00:01:38,960
Notice here the output from
our original session and from
27
00:01:38,960 --> 00:01:40,580
the SQL*Plus session.
28
00:01:40,580 --> 00:01:44,720
Since the data has not been
committed in this session,
29
00:01:44,720 --> 00:01:50,170
then it's not considered real
or available to users yet.
30
00:01:50,170 --> 00:01:52,700
Switch over.
31
00:01:52,700 --> 00:01:53,530
Type in a commit.
32
00:01:56,200 --> 00:01:58,870
Now, when this session
looks at the data,
33
00:01:58,870 --> 00:02:01,660
it sees what's expected.
34
00:02:01,660 --> 00:02:04,020
And we'll run this
statement again.
35
00:02:04,020 --> 00:02:08,100
And now, it sees
this data as well.
36
00:02:08,100 --> 00:02:11,430
Notice that this
is true of any set
37
00:02:11,430 --> 00:02:14,060
of transactions
that we might have.
38
00:02:14,060 --> 00:02:23,920
Now let's insert another
row, but we're also
39
00:02:23,920 --> 00:02:26,770
going to do other
statements as well
40
00:02:26,770 --> 00:02:30,220
to illustrate how a transaction
is packaged, if you will.
41
00:02:36,260 --> 00:02:37,680
So in this update
statement, we're
42
00:02:37,680 --> 00:02:41,840
going to update this row because
it's where ename equals Joe.
43
00:02:41,840 --> 00:02:43,590
And we're going to set
his job to analyst.
44
00:02:49,690 --> 00:02:52,720
Then finally, we're
going to delete the Fred
45
00:02:52,720 --> 00:02:55,920
row from this table.
46
00:02:55,920 --> 00:02:58,200
We haven't actually
done any changes yet,
47
00:02:58,200 --> 00:03:09,110
so let's execute these,
insert, update, and our delete.
48
00:03:09,110 --> 00:03:11,340
So what do we see?
49
00:03:11,340 --> 00:03:14,450
Well, our session shows
the insert of the Jean row,
50
00:03:14,450 --> 00:03:17,420
the update of the row
where ename equals Joe,
51
00:03:17,420 --> 00:03:21,200
and the delete of the row
where ename equals Fred.
52
00:03:21,200 --> 00:03:24,140
What does this session see?
53
00:03:24,140 --> 00:03:27,890
It sees exactly what it saw
before those three statements
54
00:03:27,890 --> 00:03:30,530
were executed because
the transaction has not
55
00:03:30,530 --> 00:03:31,520
been committed yet.
56
00:03:34,780 --> 00:03:40,580
Consequently, if we roll this
transaction back and now look
57
00:03:40,580 --> 00:03:47,920
at the table, these
two show the same data.
58
00:03:47,920 --> 00:03:56,470
So it's always necessary, as
I run these again, to commit.
59
00:03:56,470 --> 00:04:03,870
You see the rows, commit,
and now, in this session,
60
00:04:03,870 --> 00:04:06,150
the rows are consistent.
61
00:04:06,150 --> 00:04:11,010
In order to do this, Oracle
uses something called undo data.
62
00:04:11,010 --> 00:04:15,000
So the undo data
is the before image
63
00:04:15,000 --> 00:04:17,280
of the data when it's changed.
64
00:04:17,280 --> 00:04:21,030
The rows of data are actually
stored in database blocks
65
00:04:21,030 --> 00:04:22,260
in the database.
66
00:04:22,260 --> 00:04:25,740
And those blocks,
when they're changed,
67
00:04:25,740 --> 00:04:28,110
the original images
of them are moved
68
00:04:28,110 --> 00:04:31,410
to a special place in the
database called an undo table
69
00:04:31,410 --> 00:04:32,250
space.
70
00:04:32,250 --> 00:04:37,080
And there they're kept as long
as a commit has not occurred.
71
00:04:37,080 --> 00:04:41,280
That way, anytime a
user queries that data,
72
00:04:41,280 --> 00:04:44,610
they can basically be
directed toward the before
73
00:04:44,610 --> 00:04:48,210
image of the data rather
than the data that has been
74
00:04:48,210 --> 00:04:50,400
changed by another session.
5916
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.