Logo
CAR REVIEW
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
PREGNANCY
 
 
Windows Server

SQL Server 2008 R2 : Creating and Managing Stored Procedures - Using System Stored Procedures

4/23/2013 4:20:57 PM

A system stored procedure is a stored procedure that has some special characteristics. These procedures, created when SQL Server is installed or upgraded, are generally used to administer SQL Server. They shield a DBA from accessing the system catalogs directly. Some system stored procedures are used to present information from the system catalog, and others modify the system catalogs.

Note

System stored procedures seem to have fallen out of favor with Microsoft. Most of them have been listed as deprecated features in SQL Server 2008 and been replaced with T-SQL commands, or the information provided by system stored procedures is now available via the catalog views and dynamic management views. Many of the current system stored procedures may be removed in future versions of Microsoft SQL Server, so it is recommended that you avoid using many of the system stored procedures in any of your development work and modify any code currently using system stored procedures to use the alternatives.


Although many of the system stored procedures have been deprecated and are not as critical to administering SQL Server as they once were, it is still a good idea to be familiar with the basic system stored procedures. There are currently around 400 documented system stored procedures in SQL Server 2008, so it would be a tough job to learn the names and syntax for all of them. The total number of system stored procedures is more than 1,400. Some of the undocumented stored procedures are called by other procedures, and others are called from SSMS or other SQL Server tools and utility programs.

The following attributes characterize a system stored procedure:

  • The stored procedure name begins with sp_.

  • The stored procedure resides in the Resource database.

  • The procedure is defined in the sys schema.

These attributes make the procedure global, which means you can execute the procedure from any database without qualifying the database name. The procedure executes within the current database context.

Although system stored procedures reside in the Resource database, they also run in any database context when fully qualified with a database name, regardless of the current database context. For instance, sp_helpfile shows information about the files configured for the current database. In the following example, when not qualified, sp_helpfile returns file information for the master database, and when qualified with bigpubs2008.., it returns file information for the bigpubs2008 database:

exec sp_helpfile
go

name     fileid filename                                                  filegroup
size      maxsize   growth usage
-------- ------ --------------------------------------------------------- --------- --------- --------- ------ -----------
master   1      C:\MSSQL2008\MSSQL10.SQL2008UNLEASHED\MSSQL\DATA\master.mdf  PRIMARY
4096 KB  Unlimited 10%    data only
mastlog  2      C:\MSSQL2008\MSSQL10.SQL2008UNLEASHED\MSSQL\DATA\mastlog.ldf NULL
512 KB   Unlimited 10%    log only


exec bigpubs2008..sp_helpfile
go

name            fileid filename                              filegroup size
 maxsize   growth usage
-----------------------------------------------------------------------------------
------------------------
bigpubs2008     1      E:\MSSQL2008\DATA\bigpubs2008.mdf     PRIMARY   214912 KB
 Unlimited 10%    data only
bigpubs2008_log 2      E:\MSSQL2008\DATA\bigpubs2008_log.LDF NULL      504 KB
 Unlimited 10%    log only


					  

Table 1 describes the categories of system stored procedures.

Table 1. System Stored Procedure Categories
CategoryDescription
Catalog stored proceduresUsed to implement ODBC data dictionary functions and isolate ODBC applications from changes to underlying system tables.
Cursor stored proceduresUsed to implement cursor variable functionality.
Database engine stored proceduresUsed for general maintenance of the SQL Server Database Engine.
Database mail stored proceduresUsed to perform email operations from within an instance of SQL Server.
Database maintenance plan proceduresUsed to set up core database maintenance tasks.
Distributed queries stored proceduresUsed to link remote servers and manage distributed queries.
Full-text search stored proceduresUsed to implement and query full-text indexes.
Log shipping stored proceduresUsed to configure, modify, and monitor log shipping configurations.
Automation stored proceduresAllow OLE automation objects to be used within a T-SQL batch.
Notification services stored proceduresUsed to manage SQL Server 2008 Notification Services.
Replication stored proceduresUsed to manage replication.
Security stored proceduresUsed to manage security, such as login IDs, usernames, and so on.
SQL Server Profiler stored proceduresUsed by SQL Server Profiler to monitor performance and activity.
SQL Server Agent stored proceduresUsed by SQL Server Agent to manage scheduled and event-driven activities.
Web task stored proceduresUsed for creating web pages.
XML stored proceduresUsed for XML text management.
General extended stored proceduresProvide an interface from an instance of SQL Server to external programs for various maintenance activities (for example, xp_sqlmaint)

Some of the more useful system stored procedures are listed in Table 2.

Table 2. Useful System Stored Procedures
Procedure NameDescription
sp_who and sp_who2Return information about current connections to SQL Server.
sp_help [object_name]Lists the objects in a database or returns information about a specified object.
sp_helpdbReturns a list of databases or information about a specified database.
sp_configureLists or changes configuration settings.
Other -----------------
- Windows Server 2003 : Windows Firewall (part 3) - Service Pack Firewall Modifications - Modifying firewall behavior using the Windows Firewall INF file and unattend.txt
- Windows Server 2003 : Windows Firewall (part 2) - Service Pack Firewall Modifications - Modifications
- Windows Server 2003 : Windows Firewall (part 1) - Internet Connection Firewall
- Windows Server 2003 on HP ProLiant Servers : Server Placement (part 3) - Flexible Single Master Operations (FSMO) Placement
- Windows Server 2003 on HP ProLiant Servers : Server Placement (part 2) - DC Placement, GC Placement
- Windows Server 2003 on HP ProLiant Servers : Server Placement (part 1) - DNS Placement, Site Affinity
- Managing SharePoint 2010 with Windows PowerShell : Managing SharePoint 2010 Sites (part 2)
- Managing SharePoint 2010 with Windows PowerShell : Managing SharePoint 2010 Sites (part 1)
- System Center Configuration Manager 2007 : Reporting Configuration (part 3) - Console Reporting Links, Relational Database Concepts
- System Center Configuration Manager 2007 : Reporting Configuration (part 2) - Copying ConfigMgr Classic Reports to SQL Reporting Services, Report Categories
- System Center Configuration Manager 2007 : Reporting Configuration (part 1) - Configuring the Reporting Point for Classic Reporting, SRS Reporting
- System Center Configuration Manager 2007 : ConfigMgr Classic Reports Versus SQL Reporting Services
- Deploying the Client for Microsoft Exchange Server 2007 : Deploying with Microsoft Systems Management Server, Managing Postdeployment Tasks
- Deploying the Client for Microsoft Exchange Server 2007 : Installing the Exchange Client, Pushing Client Software with Windows Server 2003 Group Policies
- Integrating BizTalk Server 2010 and Microsoft Dynamics CRM : Communicating from Dynamics CRM to BizTalk Server (part 3) - Registering the plugin, Testing the plugin
- Integrating BizTalk Server 2010 and Microsoft Dynamics CRM : Communicating from Dynamics CRM to BizTalk Server (part 2) - Writing the Dynamics CRM plugin
- Integrating BizTalk Server 2010 and Microsoft Dynamics CRM : Communicating from Dynamics CRM to BizTalk Server (part 1) - Setup
- SharePoint 2010 : Farm Governance - Configuring a Managed account
- SharePoint 2010 : Farm Governance - Administering SharePoint Designer
- SQL Server 2008 R2 : Creating and Managing Stored Procedures - Debugging Stored Procedures Using SQL Server Management Studio
 
 
Most view of day
- Editing Digital Video with Windows Live Movie Maker (part 6) - Editing Your Video - Trimming Video and Audio
- Integrating BizTalk Server 2010 and Microsoft Dynamics CRM : Communicating from BizTalk Server to Dynamics CRM (part 5) - Generating a proxy service
- Managing Client Protection : Microsoft Forefront Client Security
- Windows Phone 8 : Configuring Basic Device Settings - Passwords and Screen Timeouts (part 2) - Enabling a Password
- Windows Server 2012 Administration : Managing Printers with the Print Management Console (part 2) - Adding New Printers as Network Shared Resources
- Microsoft Content Management Server : Implementing Server-Side Validation
- BizTalk Server 2009 : Use The Business Rule Engine (part 2) - What Are the Artifacts That Constitute a Business Rule?
- Adobe Dreamweaver CS5 : Working with Multimedia and Online Tools - Using Plug-ins
- Microsoft Exchange Server 2010 : Creating and Managing Accepted Domains (part 1) - Viewing Accepted Domains
- Microsoft Dynamic AX 2009 : Report Customization (part 2) - Adding Promotional Materials to an Invoice Report
Top 10
- Windows Phone 8 : Scheduled Tasks - Scheduled Task API Limitations
- Windows Phone 8 : Scheduled Tasks - Updating Tiles Using a Scheduled Task Agent
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 5) - Editing an Existing To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 4) - Creating the To-Do Item Shell Tile, Saving a To-Do Item
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 3) - Debugging Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 2) - TodoService, TodoItemViewModel
- Windows Phone 8 : Scheduled Tasks - To-Do List Scheduled Task Sample (part 1) - TodoItem,TodoDataContext
- Windows Phone 8 : Scheduled Tasks - Using Scheduled Tasks
- Windows Phone 8 : Scheduled Tasks - Background Agent Types
- Windows Phone 8 : Windows Phone Toolkit Animated Page Transitions - Reusing the Transition Attached Properties
 
 
Windows XP
Windows Vista
Windows 7
Windows Azure
Windows Server
Windows Phone
2015 Camaro