How to Change the Sequence Number of a Database Mail Account within a Profile in SQL Server (T-SQL)

If you’ve already added a Database Mail account to a profile, but you now want to change the sequence number, you can do that with the sysmail_update_profileaccount_sp stored procedure.

When doing this, you need to provide the name or ID of both the account and the profile. This is because you need to specify exactly which profile/account association you want to update.

Continue reading

How SHOWPLAN_XML Works in SQL Server

In SQL Server, you can use the SET SHOWPLAN_XML statement to return detailed information about how a T-SQL statement will be executed, in the form of a well-defined XML document.

It’s similar to SHOWPLAN_ALL, except that SHOWPLAN_ALL returns its data set of rows that form a hierarchical tree.

You can set SHOWPLAN_XML to either ON or OFF.

When SHOWPLAN_XML is ON, all subsequent T-SQL statements are not executed. Instead SQL Server returns execution information for the statement (without executing it).

Continue reading

SQL Server Error 4104: The multi-part identifier could not be bound.

If you get an error telling you that the “The multi-part identifier could not be bound.”, it usually means that you’re prefixing one or more columns with either a table that isn’t included in your query, or an alias that you haven’t actually assigned to a table.

Fortunately, the error message shows you which multi-part identifier is causing the problem.

Continue reading

Find the Associations Between Database Mail Accounts and Database Principals in SQL Server (T-SQL)

In SQL Server, you can use the sysmail_help_principalprofile_sp stored procedure on the msdb database to retrieve a list of all associations between Database Mail accounts and database principals.

You can also return account info based on the principal name/ID or the profile name/ID.

Continue reading

3 Ways to use ALL in SQL Server

You might be familiar with the ALL option in SQL Server. Perhaps you’ve used it along with the UNION operator to include any duplicates that might be returned in the result set.

But did you know that ALL can also be used in two other contexts?

ALL can be used in the following three contexts:

  • As an argument to the SELECT clause.
  • As an argument to the UNION clause.
  • As a logical operator when comparing a scalar value with a single-column set of values.

Examples of each of these contexts follows.

Continue reading

SQL Server ALL Operator Explained

In SQL Server, the ALL operator can be used with a subquery to compare a scalar value with a single-column set of values returned by the subquery.

It’s also true that the SELECT clause and UNION operator both accept an ALL argument, although this usage has a different purpose (allows duplicates in the result set).

Below are examples of using the ALL operator with a subquery.

Continue reading