Protect Your T-SQL Objects from Deletion

Downloads
95775.zip

DBAs often create T-SQL stored objects (e.g., stored procedures, functions) in system databases to help with backup, reindexing, analyzing, and other database administration and maintenance tasks. Such objects usually reside in the master database. Because these objects are owned by the DBO user, they're created and marked as user objects. Hence, they're prone to deletions by other people who don't know that the objects are being used by DBAs.

I created a stored procedure, sp_markAllMasterDBasSystem, that can help prevent the deletion of these objects. It marks all nonsystem objects (i.e., objects marked as "non MS Shipped

Objects") as system objects. As Listing 1 shows, sp_markAllMasterDBasSystem uses the undocumented stored procedure, sp_MS_marksystemObject, for this job.

I tested sp_markAllMasterDBasSystem on SQL Server 2005 Developer Edition SP1 and SQL Server 2000 Enterprise Edition SP1. You need to compile this stored procedure in each system database.

If you create T-SQL objects to help with your database administration and maintenance tasks, give sp_markAllMasterDBasSystem a try. It will protect the objects you worked so hard to create.
—Eli Leiba

See Associated Figure

Discuss this Article 1

gweaver13
on Jun 1, 2007
I hope I never have to resort to something like this. I try to keep users who might tend to drop objects from having such permissions in system databases. That's the first level of protection. And the objects are all in source control and can be easily redeployed if necessary--the second level of protection. Restoring a backup of the master database is not pleasant in terms of downtime, it would be a third level. I'd prefer to let MS mark its own objects as system objects and leave mine alone. But maybe I'd feel differently if I were in Eli's shoes.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottOur Experts will show you:
• Common SQL Server
Problems
• Best Practices for T-SQL
• SQL Server Integration
Services
• Database Development

Come See Mike Otey & Tim Ford in Person!

Early Registration Now Open

From the Blogs
May 9, 2013
blog

My ISO 8601-Compliant Signature 2

My family recently just "officially" announced that we're in the process of adopting a child from South Africa. We're quite excited, of course, but there's a ton of paperwork to do—along with the need for gobs of signatures....More
May 8, 2013
blog

Use SSIS for ETL from Hadoop

In this blog post, Mark Kromer walks you through using SSIS as a way to use ETL techniques using Microsoft's Hadoop on Windows (HDInsight) as a source using Hive connectors...More
Vision road sign
May 6, 2013
blog

Cheaters Never Win, Even in TPC Benchmarks

In this portion of the series on database benchmarking, I want to tell you about one of my favorite aspects of the TPC benchmarks – CHEATING....More
SQL Server Pro Forums

Get answers to questions, share tips, and engage with the SQL Server community in our Forums.