CategorySQL Server

Query to Find Database and Log File Information

I have recently been dealing with a situation with a client where the transaction log has become an issue.  Naturally during the research portion of trying to figure out what is wrong I wanted to find things like the size of the transaction log or what the autogrowth is set to.  You can find out much of this information through the UI relatively easily.  However, it becomes a pain when you are...

Database Recovery Models

Database recovery is a very important thing, especially to DBA’s, and the occasional developer who screws something up.  Please note, I am a developer and I would NEVER mess ANYTHING up in a database.  I treat all databases equally and with respect.  Anyway, we are getting off track.  There are three recovery models: Simple, Full and Bulk-Logged. Simple:  This method does not do log backups...

Query SQL Server Job Tables

If you have ever wanted to query the SQL Server job tables then you know they are a little cryptic. The following query will assist you in getting some useful information out of those tables. I recently wanted to be able to query these tables and get the error for when there was a failure during the running of the job. This can be accomplished using this query and just adding another couple of...

Multiple CTEs in One Query

CTEs are a great thing to use in your query.  They are an excellent way to consolidate code and make it readable as well as create a “view” inside of your code.  One great thing I have used them for many times was to pick out the max date associated with a set of key values.  So let’s say there is a table that has a column called ID, Quantity and Date.  And in this table there are duplicate IDs...

Script Indexes With Your Tables

Scripting tables inside of SQL Server Management Studio is a very simple task.  Just right click and select script table.  The problem is that, but default, the indexes on a table are not part of the script.  Rather than scripting the indexes separately from the table you can tell management studio that you want the indexes included.  Click on Tools then Options and expand the SQL Server Object...

Select NULL AS Max or Min in SQL Query

By default the functions MAX and MIN do not count NULL in their evaluation of your data.  If we have a column containing only dates for instance and there is a NULL date, MAX and MIN will both ignore that value.  For instance, take the following data set as an example. WorkID    StoreID       EndDate ———– ———–...

Select NULL AS Max or Min in SQL Query

By default the functions MAX and MIN do not count NULL in their evaluation of your data.  If we have a column containing only dates for instance and there is a NULL date, MAX and MIN will both ignore that value.  For instance, take the following data set as an example. WorkID    StoreID       EndDate ———– ———–...

Truncating A Replicated Table

On a recent project that I was working on we came across an issue where we needed to replicate several databases on a new server.  Much of the ETL had places where tables were truncated and reloaded.  Normally this is not an issue at all, simply TRUNCATE TABLE and away you go.  This does however cause a problem when you have a replicated database.  According to the Microsoft documentation, which...

CREATE SCHEMA Syntax Error

Recently while creating a script to migrate the new holding tables over to the stage and production machines I ran into a little issue.  The holding table we are using in this case houses several different sets of data for our migration project.  Tables that are used only for going from the old system to the new (which will be going away in a few months) and tables that will be used in the future...

Comma Delimited List with COALESCE

There may be a day when you need to create your own comma delimited list from data contained in a SQL table.  Sure you could build a cursor and go through each row adding a comma after each record.  The good news is that there is an alternative.  The better news is that this method is easier, faster and takes MUCH less code.  COALESCE in SQL has many uses and building a list is one of them...

Bradley Schacht

Bradley Schacht is a Principal Program Manager on the Microsoft Fabric product team based in Jacksonville, FL. Bradley is a former consultant, trainer, and has authored 5 SQL Server and Power BI books, most recently the Microsoft Power BI Quick Start Guide. As a member of the Microsoft Fabric product team, Bradley works directly with customers to solve some of their most complex data problems and helps shape the future of Microsoft Fabric. He frequently presents at community events around the country, is a contributor to sites such as SQLServerCentral.com, and is a member of the Jacksonville SQL Server User Group (JSSUG).

Follow Me