Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

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

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
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
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server