Author Archives: Bob L

Using INSTEAD OF Triggers to enable updatable views

A common misconception with SQL Server views is that only indexed views can provide update capability. Actually, any view that is schema-bound can be enabled for update by simply using an “INSTEAD OF” trigger.  Although an indexed view may also … Continue reading

Posted in Uncategorized | Leave a comment

Solving Sudoku with T-SQL

Note: This is an update to the earlier post to include the query to actually display the solved puzzle (for the skeptics… ) Recently I had to make a short trip and took a look at a Sudoku puzzle in … Continue reading

Posted in Problem Solving, SQL Server, SQL Tips and Techniques | Tagged , | 1 Comment

Creating a 3-way 10 Gbe Cluster without a switch– Part 1

After finishing the PhD, I’m back into the lab to test out some new high-speed computing experiments. Recently, I retrieved one of my servers from co-location and put it back into my home-office lab giving me 3 servers with Fusion-IO … Continue reading

Posted in Uncategorized | Leave a comment

Generating a Type-2 Dimension from Multiple Tables with Effective Dates

In slowly changing (SCD) dimensions, type-2 attributes involves ending a dimension row when the attribute value changes with the current date and creating a new row starting from the current date. While this works great to capture history once a … Continue reading

Posted in Uncategorized | Leave a comment

Dealing with a corrupt transaction log in SQL Server

I just went through the experience of a corrupted transaction log for a large SQL Server database. It was actually not as bad as I thought it would be. I ended up restoring from a backup and then putting the … Continue reading

Posted in Uncategorized | Leave a comment

Normalizing time-series data using a table function in SQL

Recently I had to normalize quarterly, monthly, and ad-hoc reported metrics into daily rows in order to do correlative analysis. Below is the function that I came up with. The idea is to generate values that are in line with … Continue reading

Posted in SQL Server, SQL Tips and Techniques | Tagged | Leave a comment

Converting Hyper-V machines from Windows 2008 R2 to Windows 2012 R2

I am posting this because it wasn’t obvious just from searching the knowledge base. I was recently converting some VMs running under Windows 2008 R2 to Windows 2012 R2 and dismayed to find out that I could not import the … Continue reading

Posted in Hyper-v, Virtualization, Windows Server, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2 | Tagged | Leave a comment

Moving Databases from One Instance to Another Painlessly (Attach Statement Generator)

If you’ve ever had a bunch of databases and need to just move them to another instance without having to manually do the attach, these two scripts may be helpful. I recently was faced with this situation and have learned … Continue reading

Posted in SQL Server, SQL Tips and Techniques | Tagged | 2 Comments

Script to auto-add surrogate primary keys

Here’s an example of how to use information_schema tables to automatically add clustered primary surrogate keys select ‘alter table ‘ +  table_name + ‘ add ‘ + table_name + ‘_Id int identity;’ from INFORMATION_SCHEMA.tables t where not exists (select 0from … Continue reading

Posted in SQL Server | Tagged | Leave a comment

Auto-discovery of data relationships minus referential integrity

My experience is that unfortunately far too many databases lack referential integrity in the schema. There are a few reasons for this, almost all of them bad. One of the worse is the “our application controls integrity” rationale with a … Continue reading

Posted in SQL Server | Tagged | Leave a comment