Dropping or modifying a column in SQL Server can look straightforward, but it often isn’t. That column might be referenced by other objects in the database, and removing it without checking can break things silently. Unlike dropping a whole table, where SQL Server is very strict about dependencies, column-level references are not always enforced or even tracked. That’s why it’s important to do some homework before making the change.
triggers
3 Ways to List all Triggers for a Given Table in PostgreSQL
Here are three options for listing out the triggers for a given table in PostgreSQL.
2 Ways to List all Triggers in a PostgreSQL Database
Here are two options for listing out the triggers in a PostgreSQL database.
List All Triggers in Oracle Database
Oracle Database includes several views that contain information about triggers in the database. We can use these views to return a list of triggers.
Execute a Trigger Only When Certain Columns are Updated (SQL Server)
SQL Server has the UPDATE() function that you can use within your DML triggers to check whether or not a specific column has been updated.
While this function only accepts one column, there’s nothing to stop you from including multiple UPDATE() clauses with AND or OR to test for multiple column updates.
How to Execute a Trigger Only When a Specific Column is Updated (SQL Server)
In SQL Server, you can create DML triggers that execute code only when a specific column is updated.
The trigger still fires, but you can test whether or not a specific column was updated, and then run code only if that column was updated.
You can do this by using the UPDATE() function inside your trigger. This function accepts the column name as its argument. It returns a boolean.
Send Email from a Trigger in SQL Server (T-SQL)
If you find yourself needing to send an email automatically upon certain events occurring in SQL Server, you can do this via a trigger.
For example, you could automatically send an email when somebody deletes or updates a record from a table, etc.
To do this, you need to create a trigger that includes code for sending the email upon the required event.
Create an “Instead Of” Trigger in SQL Server
When you create a trigger in SQL Server, you have the option of firing it in conjunction with the triggering statement (i.e. the SQL statement that fired the trigger), or firing it instead of that statement.
To fire the trigger instead of the triggering statement, use INSTEAD OF argument.
This is in contrast to using the FOR or AFTER arguments. When you use those arguments, the trigger fires only when all operations specified in the triggering SQL statement have launched successfully.
Create a DML Trigger in SQL Server
In SQL Server, you can use the CREATE TRIGGER statement to create a trigger.
A trigger is a special type of stored procedure that automatically runs when an event occurs in the database server.
You can create a DML trigger, a DDL trigger, or a logon trigger.
This article provides an example of creating a DML trigger.
Limiting Simultaneous User Sessions for a Specific Login in SQL Server
In SQL Server, you can use a logon trigger to audit and control server sessions, such as track login activity, restrict logins to SQL Server, or limit the number of sessions for a specific login.
This article provides an example of using a logon trigger to limit the number of simultaneous sessions for a specific login.