Sometimes we want to send an email when something suspicious happens in a database. Oracle is able to natively send emails.
Aggregate data that match a condition
How to aggregate data that match a given condition. How to perform different aggregations of data that match different conditions, in a single query. Includes convenient SQLite shortcuts.
Find texts that contain HTML tags
How to select text values that contain HTML tags. How to disallow inserting texts that contain HTML tags.
Get distinct values that are stored in multiple columns
Getting a list of unique values from a column is easy. But if the same type of values are written on multiple columns and we want to eliminate duplicates, this requires a little trick.
SQL Server: Send alerts via email
Sometimes we want to send an email when something suspicious happens in a database. SQL Server is able to natively send emails.
Db2 triggers: FOR EACH ROW, FOR EACH STATEMENT, DB2ROW, DB2SQL
There is some confusion about the FOR EACH
, the MODE
, and the BEFORE
/ AFTER
clauses of Db2 CREATE TRIGGER
. While other clauses are common to most DBMSs, MODE
is a Db2 unique feature. Their meaning is simpler than it seems.
Find rows that (don’t) contain a value from a list
How to find rows that contain, or don’t contain, a value from a list. The list may be written in the query, or stored in a table.
Find rows that have a match in another table
How to SELECT
rows from table A that have, or don’t have, a match in table B. While doing this, we’ll keep performance in mind.
Find the maximum text length in a column
How to get the length of the longest text in a column. Including Db2 specific syntax.
Grouping rows by a range of values
GROUP BY
allows us to group identical values to aggregate data. What is not obvious is that it can be easily used to group values that belong to the same range, as well.