Change Trusted State of Foreign Keys

Ever want to change those foreign keys created with NOCHECK to CHECK?  Not exactly an earth shattering requirement but having all of the foreign keys trusted helps keep the relationships in your databases solid.  Exactly what a good foreign key should be doing. Changing the foreign key to trusted does have the risk of uncovering … Continue reading Change Trusted State of Foreign Keys

UPDATE – ORDER BY and Deadlocking

I was working on a deadlocking issue a few days ago at a client  The transaction that  was continuously getting deadlocked utilized three SQL statements to checkout and return rows from a queue for the client’s application. Before going into the problem here’s a little code to setup the tables for the examples: The SQL … Continue reading UPDATE – ORDER BY and Deadlocking

The OVER() Clause

Thought I'd share a cool trick I picked up a while back with the OVER() clause.  Typically you’d use this clause with the PARTITION BY or ORDER BY arguments with the ranking functions released with SQL Server 2005. The OVER() clause though can also be used to do aggregations with a SELECT statement without a … Continue reading The OVER() Clause

Find Duplicate Foreign Keys

A few weeks back I was working on a process that would utilize foreign keys to crawl from table to table to export data from a production database to an archive database.  More on some of what went into that process probably at some point in the future. When the project was released to production … Continue reading Find Duplicate Foreign Keys

Scripting Object Level Permissions

A while ago while making changes to a client database, I needed to determine all of the object level permissions that were in the database I was working on.  The system stored procedure sp_helprotect turned out to be pretty useful in obtaining this information. The procedure accepts four parameters: They do pretty much what would … Continue reading Scripting Object Level Permissions

I Don’t Want To Use the Object Browser (sp_helptext)

Have you ever needed the definition of a view, stored procedure, or user defined function?  I sure hope you have - otherwise reading any more of this posting will be more than pointless. For those of you still with me, have you ever also not wanted to find that definition without have to browse through … Continue reading I Don’t Want To Use the Object Browser (sp_helptext)

Incrementing Values

Occasionally, I run across procedures that mimic the functionality of the IDENTITY property.  There are always various reasons for these procedures to exist, some valid and some not quite so.  Recently while trying to tune one of these procedures that someone had added interesting locking hints to a creative rewrite to the procedure was suggested. … Continue reading Incrementing Values