Warning: preg_match(): Unknown modifier 'b' in /mnt/datadisk/www/src/Controllers/PostController.php on line 206 SQL Server undocumented extended procedures — Dirceu ResendeSkip to content
In this post, I will comment on some SQL Server extended procedures that are very useful. Until this post, I didn't find any official Microsoft documentation about this, so I decided to comment on it, in addition to demonstrating some examples.
An extended procedure (XP) is a link to a dynamic library (DLL), programmed using the SQL Server Open Data Services API and is used to extend the functionalities of SQL Server. You can use the various procedures that come with SQL Server or create your own extended procedures using the C or C++ programming languages.
Currently, there is not much incentive to use these procedures, as they have been deprecated and should be removed in some future version of SQL Server. The most viable alternative for replacing XP Procedures is the use of procedures SQL CLR.
However, I couldn't miss the opportunity to comment on these SP's, which have always helped me on several occasions and I still see many routines using them.
To view the list of extended procedures present in your installation, simply run the command below:
EXEC master.dbo.sp_helpextendedproc
XP Procedures - sp_helpextendedproc
sp_MSgetversion
View information
This procedure can be used to return the current version of SQL Server.
Usage example:
EXEC master..sp_MSgetversion
Procedures XP - sp_MSgetversion
Workaround:
SELECT @@version
xp_dirtree
View information
This procedure can be used to list all folders and subfolders (recursively) from a given directory.
Usage example:
EXEC master..xp_dirtree 'C:\'
XP Procedures - xp_dirtree
xp_subdirs
View information
This procedure can be used to return directories (non-recursive) from an informed directory. Compared to the xp_dirtree procedure, it only returns rows where the node depth = 1.
Usage example:
EXEC master.dbo.xp_subdirs 'C:\Users\'
Procedures XP - xp_subdirs
xp_enum_oledb_providers
View information
This procedure can be used to return all available OLE DB providers. It returns the provider name, parse name, and provider description.
Usage example:
EXEC master..xp_enum_oledb_providers
Procedures XP - xp_enum_oledb_providers
xp_enumerrorlogs
View information
This procedure can be used to return all error log files and change dates.
Usage example:
EXEC master.dbo.xp_enumerrorlogs
Procedures XP - xp_enumerrorlogs
xp_readerrorlog
View information
This procedure can be used to read the SQL Server error log file. As an optional parameter, you can enter the # of the file. If not informed, it will show the current log.
Parameter list:
1st parameter: Number of the log file you want to view (0 = Current, 1 = Archive #1, 2 = Archive #2)
2nd parameter: Log file type (1 or NULL for error log, 2 for SQL Agent log)
3rd parameter: The string you would like to search for
4th parameter: Another string to refine the already filtered result
5th parameter: Log start date
6th parameter: Log end date
7th parameter: Ordering of results (‘asc’ = ascending, ‘desc’ = descending)
This procedure can be used to delete backup or report files. Although the name seems like it can delete any file, it is restricted to only backup files (BAK) and reports (RPT).
Usage example:
EXEC master.dbo.xp_delete_file
0, -- (0 = Arquivo de backup, 1 = Arquivo de report)
'C:\Backups\', -- diretório (terminando com "\")
'bak', -- extensão do arquivo (sem o ".")
'2015-08-31', -- data de corte para deletar
1 -- flag para subdiretórios (1 = incluir sub-diretórios, 0 = não incluir)
Procedures XP - sp_delete_file
xp_fixeddrives
View information
This procedure can be used to list all physical disk units or mapped drives, informing the free space.
Usage example:
EXEC master.dbo.xp_fixeddrives
Procedures XP - xp_fixeddrives
xp_availablemedia
View information
This procedure can be used to list all backup units connected to the server. If you do not have any drives, SP will return all disk drives.
Usage example:
EXEC master.dbo.xp_availablemedia
Procedures XP - xp_availablemedia
xp_getnetname
View information
This procedure can be used to return the WINS name of the machine where your session is connected.
Usage example:
EXEC master..xp_getnetname
Procedures XP - xp_getnetname
xp_regdeletekey
View information
This procedure can be used to remove a key in the Windows Registry from the SQL Server installation. Be very careful when using this procedure, as it may damage the Windows installation on that server.
This procedure can be used to remove a specific value from a key in the Windows Registry of the SQL Server installation. Be very careful when using this procedure, as it may damage the Windows installation on that server.
This procedure can be used to write a specific value of a key to the Windows Registry of the SQL Server installation. Be very careful when using this procedure, as it may damage the Windows installation on that server.
Usage example:
EXEC master..xp_regwrite
@rootkey = 'HKEY_LOCAL_MACHINE',
@key = 'SOFTWARE\Teste_Dirceu',
@value_name = 'Flamengo na Copa do Brasil 2015',
@type = 'REG_SZ',
@value = 'Eliminado pelo Vasco'
Procedures XP - xp_regwrite_1
Procedures XP - xp_regwrite_2
xp_cmdshell
View information
Allows you to run any Command Prompt (DOS) command on the server. Be very careful when using this procedure, as it may damage the Windows installation on that server.
To use this command, it is necessary to enable this feature, as if misused, it can seriously damage your installation:
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1 -- 0 para desativar
GO
RECONFIGURE
GO
Comentários (0)
Carregando comentários…