Versatile Sp_

Downloads
25586.zip

The ability to use the sp_ prefix to identify views and procedures in the master database that have a special property is interesting. Many people think that sp stands for system procedure. It actually stands for special object, meaning that an object named with the sp_ prefix has some special capabilities, such as the ability to be referenced from any database without requiring qualification by the owner name or database name. You can even use sp_ to create tables that you can access from any database. Because tables don't reference other objects, you might not be concerned that a table with the sp_ prefix can refer only to objects in the database it's created in. However, consider the table that the code in Listing A creates. You can insert into and select from this table from any database, but the default value db_name() will always reference the master database.

At times, you might want to be able to reference a view or table from any database without having to use the fully qualified name. If you don't need to reference your current database, you might find the trick of using sp_ to name objects other than procedures useful. However, if you're used to thinking that sp means system procedure instead of special object, you might find it hard to use this naming convention to refer to a view or table.

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.