Finding users who never logins is not trivial in SQL Server. But we can do it by creating a logon trigger.
Category: SQL Server
SQL Server: Writing an HTML encode function
Sometimes we need to extract a text from the database to show it in a web page. The text should be showed as is, including any HTML tags and special characters. Normally the encoding is done by a web application, but there are cases when an SQL string is expected to return HTML encoded texts.
SQL Server: How to count occurrences of a substring in a string
Sometimes you want to count all occurrences of a substring into a bigger string. For example, you may want to count all occurrences of a name in a text. This can be done, but it’s not straight-forward because SQL Server doesn’t have a specific function to do it.
SQL Server: Concatenate strings (NULL-safe)
There are several ways to concatenate strings in SQL, and they mainly differ in how they handle NULL
values.
Creating UNSIGNED columns in SQL Server
Some DBMSs, like MariaDB and MySQL, allow to create UNSIGNED
columns. SQL Server doesn’t support unsigned integers. Let’s see what we can do instead.
SQL Server: Handle errors
SQL Server allows to handle errors with TRY ... CATCH
blocks, and provides several statements to get information about the error that is being handled.
SQL Server: Raise errors and warnings
Transact-SQL provides facilities to raise errors and warnings, as well as handling them. Here’s an introduction to this subject.
SQL Server: CHECKSUM() vs CHECKSUM_BINARY() vs HASHBYTES()
SQL Server has at least three functions to create checksums or hashes: CHECKSUM()
, CHECKSUM_BINARY()
, and HASHBYTES()
. Here we discuss what differences exist between them, and how to choose the proper function for a specific use case.
SQL Server extended properties (comments)
Most DBMSs allow to read and write comments about tables, columns and other database objects. SQL Server has a more complex feature called Extended Properties.
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.