Creating Unique Constraints

Unique constraint on a column to prevent duplicate entry on a column. Using SQL Server Management Studio In Object Explorer, right-click the table to which you want to add a unique constraint, and click Design. On the Table Designer menu, click Indexes/Keys. In the Indexes/Keys dialog box, click Add. In the grid under General, click Type and choose Unique Key from the drop-down list box to the right... » read more

TSQL: Replicas Database

Query to return info about replicas. Query to return a list of Primary Replicas databases. Query to return a list of Non-Primary Replicas databases.

TSQL Error Handling

Example 1 Example 2 Sources: https://docs.microsoft.com/en-us/sql/t-sql/language-elements/raiserror-transact-sql?view=sql-server-ver15

TSQL String Split

Examples A. Split comma-separated value string Parse a comma-separated list of values and return all non-empty tokens. STRING_SPLIT will return empty string if there is nothing between separator. Condition RTRIM(value) <> ” will remove empty tokens. B. Split comma-separated value string in a column Product table has a column with comma-separate list of tags shown... » read more

TSQL Convert

DATETIME to DATE and TIME Should I use CAST or Convert? Unless you have some specific formatting requirements you’re trying to address during the conversion, I would stick with using the CAST function.  There are several reason I can think of: CAST is ANSI-SQL compliant; therefore, more apt to be used in other database implementation.... » read more

TSQL CAST

INT to VARCHAR DATETIME to DATE and TIME Should I use CAST or Convert? Unless you have some specific formatting requirements you’re trying to address during the conversion, I would stick with using the CAST function.  There are several reason I can think of: CAST is ANSI-SQL compliant; therefore, more apt to be used in... » read more