SQL Server Queries to help you find fields and values

If you ever find yourself looking at a SQL server DB with no diagram, no integrity rules, and over a decade of legacy stuff lurking somewhere deep within, you may want to make use of the following two queries that will help you to find your way around and...

Update SQL Server and return ID of row updated

So you want to update a single row in your table and then return the row identifier that was affected, here’s one way of going about it. Remember SCOPE_IDENTITY() is about inserting so as we are updating here we need a little something different. This will...

Get DatabaseID from SQL Server

My usual way to find the ID of a database to reliably filter a trace running in profiler is to look through the sysobjects table in master. I found this way is far nicer select db_id(‘yourdatabasename’) DOH!

Create a million rows in no time at all

Perhaps there’s a point to this, but not for me today – but maybe in future or for you today? create table #t (a int) create table #A (a int, b int) create table #B (a int, b int, C int) create table #C (a int, b int, c int, D int) create table #D (a int,...