Sql-Server

SDU Tools: Is XACT_ABORT on in my SQL Server session?

XACT_ABORT is one of the least well understood options that you can configure in a SQL Server session. Yet it’s very important. XACT_ABORT makes statement-terminating errors become batch-terminating errors. Without it, even within a transaction, many errors only terminate the statement that they occur in, and control passes to the next statement within the transaction, not out of the transaction.

In nearly every stored procedure that I write, the template includes the following lines:

2018-10-10

SQL Server Indexing for Developers - new online on-demand training course

Do you need to understand SQL Server indexing in detail? Do you know someone else who needs to? Either way, our new SQL Server Indexing for Developers course could be just what you’re looking for.

It’s detailed. It has a full set of practical exercises (hands-on labs) with downloadable test data and scripts.

The best part is it’s on sale until October 31st for $195 USD as an introductory special.

2018-10-08

Shortcut: XML editor in SSMS and increasing XML output size

Most people use SQL Server Management Studio (SSMS) to edit SQL queries. No big surprise there. The files will have a file type of .sql.

But what many people don’t understand is that SSMS inherits many of its underlying Visual Studio’s abilities to edit other document types.

For example, if you open a .txt text file, you can edit it just fine, and you can also include files like this in SSMS script projects. That can be useful for additional notes and documentation.

2018-10-04

SDU Tools: Is a SQL Server Agent Job Running ?

I often need to write scripts that interact with SQL Server Agent jobs. One thing that I regularly need to know is if a particular job is currently running.

In our free SDU Tools for developers and DBAs,  we added a function IsJobRunning to work that out.

You can see the outcome in the main image above.

You can see it in action here:

YouTube Video

2018-10-03

SQL Server Q&A: Does SQL Server have a boolean data type? Is that a bit?

Simple answer: No

SQL Server has a concept of boolean data type but it doesn’t have an actual boolean data type. I can’t declare a column with a boolean data type, and I can’t use it that way. However, the concept of boolean data is present.

For example, if I write the following:

SELECT * FROM Sometable WHERE Somecolumn = Someothercolumn

the outcome of that comparison is TRUE, FALSE, or (don’t forget) NULL. And remember that NULL isn’t a value; it’s the lack of a value. WHERE clauses are satisfied when the value of the predicate is TRUE.

2018-10-01

Shortcut: Connecting to Azure Storage and other services in SSMS

SQL Server Management Studio (SSMS) is a great tool for working with SQL Server relational databases but it can do much more than that.

In Object Explorer, note that you can easily connect to other types of services:

For a long time, it has been able to connect to Analysis Services to manage SSAS databases, both tabular and multi-dimensional. It can connect to Integration Services but that’s to the older style interface for SSIS. Nowadays, you should use the SSIS Catalog instead. There are a few items that you can configure via the Reporting Services connection as well.

2018-09-27

SDU Tools: Convert a hexadecimal character string to an integer in T-SQL

I mentioned in a previous post about how I sometimes need to work with binary strings in SQL Server using T-SQL.  The literal values are hexadecimal strings. T-SQL doesn’t have a simple function to just convert one of these character-pair strings to an integer.

In our free SDU Tools for developers and DBAs, as well as the HexCharStringToChar function, we added a function HexCharStringToInt to do just this.

You can see the outcome in the main image above.

2018-09-26

SQL: Implementing Optimistic Concurrency in SQL Server with RowVersion

It’s common to need to have a way to read a row of data from a table, to be able to modify it, and to then update it back into the table, but only if it hasn’t been changed in the meantime. But we don’t want to lock it in the meantime. That’s the basis of optimistic concurrency. By contrast, pessimistic concurrency would hold locks the whole time. In SQL Server, you should use the rowversion data type to implement optimistic concurrency.

2018-09-24

Shortcut: Disable certificate revocation checking to start SSMS faster

If you have ever started SQL Server Management Studio in an isolated environment (ie: one with no external Internet connectivity), you’ll find that it’s slower to start.

That’s because SQL Server uses signed assemblies, and whenever an application with signed assemblies starts, it needs to check whether or not the certificate that they were signed with has been revoked. It’s not good enough to just check if it’s a valid certificate.

2018-09-20

SDU Tools: Convert a hexadecimal character string to a character in T-SQL

On occasions I have to work with binary strings in SQL Server using T-SQL.  The literal values are hexadecimal strings. T-SQL doesn’t have a simple function to just convert one of these character-pair strings to a character.

In our free SDU Tools for developers and DBAs, we added a function HexCharStringToChar to do just this.

You can see the outcome in the main image above.

You can see it in action here:

2018-09-19