Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
The-Manga-guide-to-databases.pdf
Скачиваний:
5
Добавлен:
17.11.2024
Размер:
36.39 Mб
Скачать

What Is a Transaction?

Click, click, click...

Beep

Beep

Click,

click,

clack, click...

Click, clack,

click...

You see, this one and this one are new orders.

Yes, sir. I'll add

 

Argh, show up

them to the

 

We’re finally

normally, will

database right

learning to use a

you?

away.

database, aren't we?

Tico!

 

 

 

Sorry

 

 

'bout that.

Geez!!

Gee!

*

*Hop!

126  Chapter 5

Actually,

 

For example, I wonder

I should

 

but we still

why a database can still

thank you…

have so much

operate when so many

 

 

to learn.

users are accessing it at

 

 

the same time.

 

For that matter,

 

 

the issue of

 

 

 

security also

 

 

concerns me a

 

 

bit.

 

 

 

 

Well,

 

 

 

To better

 

Apparently, you have

 

understand

 

some worries about

 

the issues,

 

 

 

 

your database.

 

 

Ahem!

 

 

 

 

 

I have done

 

 

 

a little

 

 

Sort of.

research.

Oh, yeah?

 

 

 

 

 

The title of my

 

 

 

presentation is:

 

 

 

How can a database

 

Flash!

 

 

 

let a large number

 

 

I have even

of users access it

 

 

simultaneously?

 

 

prepared

 

 

 

illustrations

 

 

 

to help your

 

 

 

understanding!

 

 

 

Gee,

 

 

that's great.

 

 

 

Database

Oh!

 

 

Theater

I love a good show!

Now let me begin.

One day, Andy

 

 

and Becky

Database

 

accessed the

 

Clap,

database at the

 

same time.

 

clap,

 

 

 

clap

 

 

Whoopee!

From this database, Andy read the Product Table, namely apples.

He then added 10 to the inventory by writing a database operation.

30 apples

I see 30

now.

Uh-huh.

I'll add 10.

I'll have 40, then.

Meanwhile, Becky also read the number of apples, 30, and added 10 herself.

But after that operation, the database shows the current number of apples as 40.

30

Just

tryin’ to

apples

help!

I see

 

30

 

now.

Is that

 

right?

I'll add 10.

I'll add 10.

 

I'll

 

have

I'll have

40,

then.

40, then.

 

40

 

apples

 

128  Chapter 5

Shouldn't it

That's

So where have

right.

the 10 apples

be 50 now?

 

gone?

 

 

Andy has

 

Think

added 10.

 

 

hard!

Becky has

 

 

added 10.

 

 

 

 

Let me see...

Eaten up.

No way! They

weren’t there to

By Cain!

begin with!

 

Me?!

j'accuse!

In order to allow

 

So the question is, how

Andy and Becky to

 

does a database control

use the database at

 

user operations?

the same time,

 

 

there must be a

He's

I'll explain that now!

In fact, in this

 

add 10.

sequence, Becky can’t

Database

 

perform any database

So 10 apples

operation while Andy’s

would never

working.

disappear.

 

mechanism to prevent

groovy!

 

inconsistencies and

 

duplications such as

 

this.

Indeed.

 

Cain's terrific today.

First of all, a database is designed to process data operations in a

lump.

Hm-hm

A unit of data operations is called a transaction.

Transaction?

In this example, a read operation, an add operation, and a write operation are processed as a single transaction.

Transaction

Read

Read

data.

data.

add 10.

add 10.

Write

Write

the

the

result.

result.

Transaction

So, Andy's

And Becky's

operations form

operations form

one transaction,

another.

130  Chapter 5