text stringlengths 1 81 | start float64 0 10.1k | duration float64 0 24.9 |
|---|---|---|
and now I can end that
particular statement | 5,531.07 | 2.93 |
I want to run after I hear
a delete on collections. | 5,534 | 4.11 |
So I'll hit Enter now, and
let me type dot schema. | 5,538.11 | 3.66 |
I can actually see this
trigger is part of my schema. | 5,541.77 | 4.71 |
I can see create trigger sell
before delete on transactions | 5,546.48 | 3.33 |
underneath the transactions table. | 5,549.81 | 3.6 |
OK, let's try putting
this into action here. | 5,553.41 | 3.27 |
Let me try actually deleting
something from our collections table. | 5,556.68 | 2.79 |
I'll say delete from collections
where the title equals | 5,559.47 | 4.62 |
"Profusion of Flowers." | 5,564.09 | 1.83 |
I want to sell this particular piece
of artwork from our collection. | 5,565.92 | 3.54 |
I'll hit semicolon here, and now
nothing seems to happen as usual, | 5,569.46 | 5.07 |
but if I select star from collections-- | 5,574.53 | 3.76 |
from collections, I
see that piece is gone. | 5,578.29 | 4.53 |
It's no longer in here, and if I
select star from transactions-- | 5,582.82 | 5.25 |
select star from transactions,
I actually see it's been sold. | 5,588.07 | 4.65 |
So automatically, I added
"Profusion of Flowers" | 5,592.72 | 3.12 |
with the action of sold
to my transactions table. | 5,595.84 | 2.97 |
I did not type insert myself. | 5,598.81 | 2.59 |
I instead created a trigger
to run this statement, | 5,601.4 | 3.56 |
insert into, whenever I
delete it on collections. | 5,604.96 | 4.76 |
Let's try one more. | 5,609.72 | 1.29 |
We want to not just be
able to sell artwork, | 5,611.01 | 1.89 |
but also add it to our
collection by buying it. | 5,612.9 | 3.36 |
So I create a trigger called buy. | 5,616.26 | 2.79 |
Let me type create
trigger "buy," and now I | 5,619.05 | 5.7 |
want to run this statement forthcoming
after an insert on collections. | 5,624.75 | 7.71 |
So I want to first insert a new item to
collections, and when I do, after I do, | 5,632.46 | 6.36 |
I want to run this query coming next. | 5,638.82 | 2.79 |
Now, I want to, for each row,
begin the statement I want to run. | 5,641.61 | 5.98 |
So as we said before, I want to
insert into the transactions table. | 5,647.59 | 4.79 |
I want to insert into the title
and action columns, just like this. | 5,652.38 | 5.71 |
Now, I want to insert some values. | 5,658.09 | 3.29 |
The values I want to insert-- | 5,661.38 | 1.68 |
well, I want to insert the new
title, the new row I've just added. | 5,663.06 | 4.35 |
So in addition to old,
we also have new when | 5,667.41 | 3.33 |
I'm talking when I'm using
a trigger on an insert. | 5,670.74 | 2.58 |
So I'll say new.title, where again, new
is the new row or rows I'm inserting, | 5,673.32 | 6.78 |
and the dot title is
a column called title. | 5,680.1 | 4.83 |
Now, here I'll say
the action was bought. | 5,684.93 | 2.43 |
We bought this artwork. | 5,687.36 | 1.71 |
I'll hit semicolon here,
and now, I'll say end | 5,689.07 | 3.18 |
to say this is the end of my statement
I want to run for every row I | 5,692.25 | 4.26 |
insert on collections. | 5,696.51 | 2.07 |
Let me hit Enter here. | 5,698.58 | 1.62 |
I've created this trigger. | 5,700.2 | 1.32 |
I can type dot schema to
see it in my actual schema. | 5,701.52 | 4.66 |
Now, let's try inserting. | 5,706.18 | 1.73 |
I'll say insert into collections. | 5,707.91 | 3.72 |
I want to insert into the
title and accession number, | 5,711.63 | 4.05 |
as well as the acquired columns here. | 5,715.68 | 3.27 |
I want to insert some new artwork. | 5,718.95 | 2.31 |
Maybe I sold Profusion of Flowers,
but now I want to just buy it back. | 5,721.26 | 3.37 |
So I'll say I'll insert "Profusion
of Flowers" is the title. | 5,724.63 | 5.88 |
The accession number was 56.257,
and the date we acquired it, well, | 5,730.51 | 6.65 |
that was in 1956/04/12. | 5,737.16 | 4.2 |
Let's hit semicolon here. | 5,741.36 | 1.95 |
Now, I'll insert, and I'll say
select star from collections. | 5,743.31 | 5.46 |
I should see Profusion of
Flowers back in my table. | 5,748.77 | 4.54 |
Now though, if I say select
star from transactions-- | 5,753.31 | 3.47 |
select star from
transactions, I should see | 5,756.78 | 3.24 |
I previously sold Profusion of
Flowers, and later bought it back. | 5,760.02 | 3.96 |
So again, I didn't run
this insert myself. | 5,763.98 | 4.06 |
I instead triggered it by making my very
own insert on the collections table. | 5,768.04 | 6.12 |
So this is the power of triggers. | 5,774.16 | 2.27 |
You're able to run
statements that I myself | 5,776.43 | 2.4 |
didn't create in response to
statements that I actually did. | 5,778.83 | 4.2 |
So let me ask here, what questions
do we have on these triggers | 5,783.03 | 4.41 |
and what they can do for us? | 5,787.44 | 1.56 |
Let's go to Simon. | 5,791.65 | 1.58 |
SIMON: I'd like to know
if there are only-- | 5,793.23 | 5.16 |
there is only one SQL
inquiry that you can write | 5,798.39 | 4.05 |
in a trigger or multiple inquiries. | 5,802.44 | 3.73 |
SPEAKER: Yeah, we saw begin
and end in our triggers | 5,806.17 | 3.53 |
here, where begin indicates
the start of our statement, | 5,809.7 | 2.59 |
and end indicates the end. | 5,812.29 | 1.73 |
You actually can have
multiple statements | 5,814.02 | 2.46 |
inside of the begin
and end separated by, | 5,816.48 | 2.97 |
of course, that usual
semicolon that we have. | 5,819.45 | 3.68 |
OK, so one final idea here
that we're getting at-- we're | 5,823.13 | 3.9 |
kind of touching at with
this transactions table is | 5,827.03 | 2.34 |
this idea of having a soft deletion. | 5,829.37 | 3.33 |
So when I dropped something
from my collections table, | 5,832.7 | 4.68 |
it actually ended up in
my transactions table, | 5,837.38 | 3.51 |
so it wasn't fully deleted in the
sense that I'm keeping a record of it | 5,840.89 | 3.6 |
somewhere else. | 5,844.49 | 1.84 |
There's also one more
way among many others | 5,846.33 | 2.6 |
to implement this idea of soft
deletions, that is not quite fully | 5,848.93 | 3.193 |
deleting something from my
database but instead keeping it | 5,852.123 | 2.417 |
around with a log that we've
removed it in some way. | 5,854.54 | 3.43 |
Let's look at this table here. | 5,857.97 | 1.97 |
I have collections, but I also
have this column called "deleted," | 5,859.94 | 5.31 |
and by default, the
value here will be 0. | 5,865.25 | 3.75 |
That is, by default, I'll add some
artwork to my collections table | 5,869 | 5.19 |
and deleted will be 0. | 5,874.19 | 2.79 |
If I want to delete a piece of
artwork though, what could I do? | 5,876.98 | 4.23 |
Instead of deleting it fully from
my table or removing the row, | 5,881.21 | 3.84 |
I could mark it as deleted. | 5,885.05 | 2.04 |
I could change the deleted
column from a 0 to a 1. | 5,887.09 | 3.54 |
Let's say I wanted to delete
Farmers Working At Dawn | 5,890.63 | 2.64 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.