All right you've got one more video here.
And this has to do with managing triggers which sounds a bit like a chapter in a self-help book but
really it has to do with how we make sure our triggers are working and mainly delete them.
So this is where the name of our trigger comes into play.
And then also I'll end with a quick warning about triggers.
So the first thing that we can do is just list the triggers that exist in a database so we can just
use show triggers to see what we have going on.
And I'll warn you this is not my warning.
I already talked about it but I'll warn you that what you get when you run this is kind of a mess to
look at.
But we can see we have in our Instagram data we have to triggers prevent cell follows.
And then you can actually see the code inside of that trigger.
And then we have capture unfollow and you can see that code as well.
And if I switched over to the other database I believe it was use trigger demo and I do show triggers.
We have one here.
This is our must be adult.
All right.
So we have that I'll switch back to my Instagram clone.
OK.
And do our show triggers just to make sure they're still there.
They shouldn't go anywhere anyways.
But we've got two of them.
So that's pretty much it to listing them.
Moving on.
So if I want to remove a trigger it's pretty simple.
It's drop trigger and then the trigger name.
So let's go back.
Let's say I want to remove this prevent cell follows.
I want to allow users to follow themselves.
So I want to get rid of that.
I'll just copy the name just so I don't have to type it.
And we just do drop trigger pre-event cell follows.
And if we do our show triggers again it's gone.
And just to verify that it works it's not just the leading trigger from show triggers lets try and trigger
it if you will with something that would have caused a problem or thrown an error in the past.
So insert into follows and we have follow word I.D. come follow me.
This is the worst part
values.
Let's Insearch one thing where they're the same.
How about seven and seven.
No problem.
So in the past that would have been a problem because that trigger but it's now gone.
OK.
So that's really all there is to managing triggers or at least all that I'm going to talk about here.
We can look at them using show and we can delete them using dropping trigger.
So that brings me to the last thing that I warned you about which is I wanted to just briefly address
a potential pickup with triggers.
This is kind of a concern that a lot of developers have and it has to do with debugging code debugging
applications that make use of triggers in your database.
So imagine that you're a developer on a team with a bunch of people and something's not working how
you expect it to.
Let's say when you insert something into a table you realize that actually two items are being created
for some reason and you have no idea why.
And you might think OK maybe that something happening on my side of the application maybe that's my
code that's that something is wrong you know with our logic on the front end with our let's say Objective
C code and you could scour that forever but you would actually never get to the core of the problem
if it was because of a trigger and triggers are kind of stealth little bugs waiting to happen because
you have no way of identifying that something is happening because of a trigger.
It happens kind of behind the scenes like remember.
Go back here with our unfollow if I can go find that way back here.
Oh boy where is that.
Here we go.
Here we had ninety nine entries created automatically when all they did was run a single line of sequel
to actually delete things and ended up creating 99 things.
Now we knew that was going to happen.
But if you have a bunch of triggers and somebody doesn't know about I'm on team or you forget about
them it can make things difficult to debug because it's basically magic happening behind the scenes
things that are hidden.
Typically you know when you're debugging your code is up in front of you you can see where the problems
are happening.
So triggers cause problems sometimes because of that and the other thing I would say is that some people
have a tendency to chain triggers together.
So with unfollowed example you could have another event trigger.
So let's say here were one follow is deleted.
We're inserting into an follows.
We could have another trigger for when something is inserted into unfollowed to do something else.
And you can chain them together and there's actually situations where believe it or not that actually
makes sense but it's kind of frowned upon by a lot of people.
So just be conscientious if you're using a lot of triggers.
Typically there's a better way of doing it without having to make use of triggers.
And if there's not then you know that it's a good use case for triggers.
I'm not saying you should never use them.
By all means they're very useful.
It's just that you should be conscientious about them and try and find ways to not use them.
OK.
So to wrap that up.
Just be aware that triggers can make debugging more difficult more problematic because stuff happens
behind the scenes.
It's not explicit when something happens.
And then also be aware that too many triggers can often be a problem and you want to avoid triggers
as much as you can.
Not at all costs or anything I'm not saying they're bad.
Just be careful with them.
All right.
So that answer some of your questions about triggers.
Hopefully you can see the utility in them and I know a lot of people are asking about preventing people
from following themselves.
So if nothing else hopefully it's nice to see that how you can actually prevent people from following
their stuff.
All right.