Quick Reference Guide - System Stored Procedures - SQL Server 2005
Quick Reference Guide - System Stored Procedures - SQL Server 2005
This is a quick reference for the usable system proc. Not all system procs are in scope, only the ones considered to be most useful. Focus is on ss2k5 system procs. Initial categories utilized are defined using http:// msdn2.microsoft.com/en-us/library/ms187961.aspx: 1. Catalog
Return name of the DLL for the specified extended stored procedure, or all extended stored procedures.
sp_helpextendedproc [ [@funcname = ] procedure ]
sp_addlogin [ @loginame = ] login [ , [ @passwd = ] password ] [ , [ @defdb = ] database ] [ , [ @deflanguage = ] language ] [ , [ @sid = ] sid ] [ , [ @encryptopt= ] encryption_option ]
[ , [ @start_run_date = ] start_run_date ] [ , [ @end_run_date = ] end_run_date ] [ , [ @start_run_time = ] start_run_time ] [ , [ @end_run_time = ] end_run_time ] [ , [ @minimum_run_duration = ] minimum_run_duration ] [ , [ @run_status = ] run_status ] [ , [ @minimum_retries = ] minimum_retries ] [ , [ @oldest_first = ] oldest_first ] [ , [ @server = ] server ] [ , [ @mode = ] mode ]
2. Database Engine 3. General Extended 4. Security 5. SQL Profiler 6. SQL Server Agent
All system stored procedures are located inside the master database, except for the SQL Server Agent stored procedures. Those are located in the msdb database, and as a result the user will either need to connect to the msdb database or issue an execute command as follows: EXEC msdb..[proc_name]
Return information about the job schedule for the specified job.
sp_help_jobschedule [ @job_id = ] job_id | [ @job_name = ] job_name [ , [ @schedule_name = ] schedule_name ] | [ , [ @schedule_id = ] schedule_id ] [ , [ @include_description = ] include_description ]
sp_addumpdevice [ @devtype = ] device_type , [ @logicalname = ] logical_name , [ @physicalname = ] physical_name [ , { [ @cntrltype = ] controller_type | [ @devstatus = ] device_status } ]
Log event in the instance error log and the server event log.
xp_logevent { error_number , message } [ , severity ]
Return information regarding the remote, linked, or replication servers for the current instance.
sp_helpserver [ [ @server = ] server ] [ , [ @optname = ] option ] [ , [ @show_topology = ] show_topology ]
Add a database user, database role, or server login to the specified role.
sp_addrolemember [ @rolename = ] role, [ @membername = ] security_account
Return information for the specified role, or all roles for the current database.
sp_helpgroup [ [ @grpname = ] role ]
Return the sort order and character set information for the current instance.
sp_helpsort
Return information for the specified remote or linked server, or all defined remote and linked servers.
sp_helplinkedsrvlogin [ [ @rmtsrvname = ] rmtsrvname ] [ , [ @locallogin = ] locallogin ]
Attach a database file to the instance. This procedure is most useful when no associated log file is available.
sp_attach_single_file_db [ @dbname= ] dbname , [ @physname= ] physical_name
Return information for the specified server login, or for all server logins.
sp_helplogins [ [ @LoginNamePattern = ] login ]
Return information for the specified domain group, or all domain groups, with access to the current database.
sp_helpntgroup [ [ @ntname= ] name ]
Returns information about the specified operator, or all operators defined for the current instance.
sp_help_operator [ [ @operator_name = ] operator_name ] [ , [ @operator_id = ] operator_id ]
Return information for the specified remote server logins, or for all remote server logins, defined on the local server.
sp_helpremotelogin [ [ @remoteserver = ] remoteserver ] [ , [ @remotename = ] remote_name ]
sp_columns [ @table_name = ] object [ , [ @table_owner = ] owner ] [ , [ @table_qualifier = ] qualifier ] [ , [ @column_name = ] column ] [ , [ @ODBCVer = ] ODBCVer ]
Alter the password of the specified application role in the current database.
sp_approlepassword [ @rolename= ] role , [ @newpwd = ] password
Return information for the specified database role, or all database roles, for the current database.
sp_helprole [ [ @rolename = ] role ]
List all databases for the current instance, including size in KB.
sp_databases
Create statistics for columns in a table, or for columns specific to indexes in a table.
sp_createstats [ [ @indexonly = ] indexonly ] [ , [ @fullscan = ] fullscan ] [ , [ @norecompute = ] norecompute ]
Create an event.
Return information for the specified database role member, or all database role members, for the current database.
sp_helprolemember [ [ @rolename = ] role ]
Display list of all tables with a defined foreign key relationship to the given primary key table.
sp_fkeys [ @pktable_name = ] pktable_name [ , [ @pktable_owner = ] pktable_owner ] [ , [ @pktable_qualifier = ] pktable_qualifier ] { , [ @fktable_name = ] fktable_name } [ , [ @fktable_owner = ] fktable_owner ] [ , [ @fktable_qualifier = ] fktable_qualifier ]
Configure the specified stored procedure to be executed when the server instance is started.
sp_procoption [ @ProcName = ] procedure , [ @OptionName = ] option , [ @OptionValue = ] value
Alter the role membership of a user in the database to use only the specified role.
sp_changegroup [ @grpname= ] role , [ @username = ] user
sp_trace_setfilter [ @traceid = ] trace_id , [ @columnid = ] column_id , [ @logical_operator = ] logical_operator , [ @comparison_operator = ] comparison_operator , [ @value = ] value
Return member information for the specified fixed server role, or all fixed server roles.
sp_helpsrvrolemember [ [ @srvrolename = ] role ]
Return information for the specified database user or role, or all database users in the current database.
sp_helpuser [ [ @name_in_db = ] security_account ]
Return name and owner on all databases for which the current user has access.
sp_MShasdbaccess
sp_start_job { [@job_name =] job_name | [@job_id =] job_id } [ , [@error_flag =] error_flag] [ , [@server_name =] server_name] [ , [@step_name =] step_name] [ , [@output_flag =] output_flag]
Deletes backup and restore entries in the msdb database for entries older than the specified date.
sp_delete_backuphistory [ @oldest_date = ] oldest_date
sp_settriggerorder [ @triggername = ] [ triggerschema. ] triggername , [ @order = ] value , [ @stmttype = ] statement_type [ , [ @namespace = ] { DATABASE | SERVER | NULL } ]
Deny specified domain login the ability to connect to the current instance.
sp_denylogin [ @loginame= ] login
Configure permissions for the specified application role in the current database.
sp_setapprole [ @rolename = ] role, [ @password = ] { encrypt Npassword } | password [ , [ @encrypt = ] { none | odbc } ] [ , [ @fCreateCookie = ] true | false ] [ , [ @cookie = ] @cookie OUTPUT ]
Author, Thomas LaRock Thomas LaRock, a member of Quests Association for SQL Server Experts, is a seasoned IT professional with almost a decade of technical and management experience. Currently serving as a database engineering team lead with ING Investment Management, Thomas has progressed through several roles at ING, including programmer, analyst, and DBA. Prior to ING, he worked at several software and consulting companies, working at customer sites in the United States and abroad. Thomas holds a MS degree in mathematics from Washington State University and is also a member of PASS and the Usability Professionals Association.
sp_executesql [ @stmt = ] stmt [ {, [@params=] N@parameter_name data_type [ [ OUT [ PUT ][,...n] } {, [ @param1 = ] value1 [ ,...n ] } ]
Return information about the specified login or all logins currently connected to the instance.
sp_who [[@login_name =] login]
Return permission information for the specified fixed server role, or all fixed server roles.
sp_srvrolepermission [ [ @srvrolename = ] role]
Return information on domain users or groups that exist as server logins, but no longer exist in the domain.
sp_validatelogins
Return information about the current state of the specified job, or all jobs.
sp_help_jobactivity [ [ @job_id = ] job_id ] | [ @job_name = ] job_name ] ] [ , [ @session_id = ] session_id ] ]
Remove a database user, database role, or server login from the specified role.
sp_droprolemember [ @rolename = ] role , [ @membername = ] security_account
Return information about the specified backup device, or all backup devices.
sp_helpdevice [ [ @devname = ] name ]
Find all your SQL Servers in your environment with our free tool download from quest.com/sqldiscovery