Copyright

Triggers in SQL: Example & Syntax

Instructor: David Gloag
When certain information is important, it is often useful to know when something happens that might affect that information. In this lesson, we'll take a look at SQL, what triggers are, where triggers are used, and their syntax.

Information - A Powerful Ally

We capture information, store information, and analyze information. Let's face it; information lets us do a lot of things. Weather information gives us insight into what we might expect over the short term; financial information shows us whether a business is profitable; and medical information leads us to new discoveries. It makes sense then that many people want to access available information. Clearly, security measures help with people that have malicious intent and simply keeps them out. But what about people that don't have malicious intent? What about the people that should be accessing the information and perhaps make a mistake? There a number of possibilities. One in particular involves a silent watchdog, a feature of SQL called triggers.

What is SQL?

Structured Query Language, or SQL for short, is a language that facilitates interaction with a database. Interaction takes place through the use of commands, which can be combined. Many types of interaction are possible, including; storing, retrieving, sorting, and searching. In other words, almost any operation you can think of, or perform on, information. SQL was first developed by IBM in the early 1970's, and later released as a product by Oracle (1979). These days, it has become a standard for database access. Many companies now use it and some even offer it as part of their product lines.

What is an SQL Trigger?

An SQL trigger is an SQL feature that provides the ability for a database to recognize and react to an external event. By external event, we mean something particular that is perhaps out of the ordinary or of interest. For example, say you are baking a cake. Further, say you set a timer that rings when the cake has finished baking. The ring would be an external event that you are interested in because it lets you know to take the cake out of the oven. A trigger is a stored piece of SQL code that gets executed when an event of interest occurs. It must be set to recognize the event and it must be told what to do when the event occurs. After that, the trigger silently waits for the particular event to occur and then automatically takes the specified action.

What are SQL Triggers Used for?

SQL triggers are used for a number of things. They include:

To unlock this lesson you must be a Study.com Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use Study.com

Become a Study.com member and start learning now.
Become a Member  Back
What teachers are saying about Study.com
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? Study.com has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account
Support