Select Page

SQL Server Articles

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...

Output SQL Queries to an email address

Once you have a user profile in SQL server 2008 that can send email saving something along the lines of the below as a job will attach a textfile containing the output of a query and send it to an email address in a rather tidy fashion.   DECLARE @Filename...

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 update a...

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!