MSSQL Undocumented Extended Stored Procedures

Pick Language to Auto Translate:
AR | BG | CA | CS | DA | DE | EL | ES | FI | FR | HI | HR | ID | IT | IW | JA | KO | LT | LV | NL | NO | PL | PT | RO | RU | SK | SR | SL | SV | TL | UK | VI | ZH | ZH-TW

MSSQL Undocumented Extended Stored Procedures

Query Analyzer can be used to run stored procedure as well as extended stored procedures. You can also write your own in with any languages that can produce a DLL file.

Many of the extended stored procedures are not documented and remember since it is not documented it means it might not be there in the future version. The frustrating part is you can not get this information in SQL Servers Books online!

Here are some examples: EXEC master..sp_MSgetversion or SELECT @@version
This extended stored procedure can be used to get the current version of Microsoft SQL Server. To get the current SQL Server version.

EXEC master..xp_dirtree 'C:\MSSQL7'
This extended stored procedure can be used to get a list of all the folders for the folder named in the XP. To get a list of all the folders in the C:\MSSQL7 folder.

EXEC master..xp_subdirs 'C:\MSSQL7'
This extended stored procedure is used to get the list of folders for the folder named in the XP. In comparison with xp_dirtree, xp_subdirs returns only those directories whose depth = 1.

EXEC master..xp_enum_oledb_providers
This extended stored procedure is used to list of all the available OLE DB providers. It returns Provider Name, Parses Name and Provider Description. To get a list of all OLE DB providers for your SQL Server.

EXEC master..xp_enumcodepages
This extended stored procedure can be used to list of all code pages, character sets and their description for your SQL Server. To see this, list.

EXEC master..xp_enumdsn
This extended stored procedure returns a list of all system DSNs and their descriptions. To get the list of system DSNs.

EXEC master..xp_enumerrorlogs
This extended stored procedure returns the list of all error logs with their last change date. To get the list of error logs.

EXEC master..xp_enumgroups
This extended stored procedure returns the list of Windows NT groups and their description. To get the list of the Windows NT groups.

EXECUTE xp_fileexist filename [, file_exists INT OUTPUT]
You can use this extended stored procedure to determine whether a particular file exists on the disk or not. The syntax for this XP is:

For example: EXEC master..xp_fileexist 'c:\boot.ini'

EXEC master..xp_fixeddrives
This very useful extended stored procedure returns the list of all hard drives and the amount of free space in Mb for each hard drive. To see the list of drives.

EXEC master..xp_getnetname
This extended stored procedure returns the WINS name of the SQL Server that you're connected to. To view the name.

EXEC master..xp_readerrorlog
This extended stored procedure returns the content of the error log file. You can find the error log file in the C:\MSSQL7\Log directory, by default. To see the text of the error log file.

EXECUTE xp_regdeletekey [@rootkey=]'rootkey', [@key=]'key'
This extended stored procedure will delete an entire key from the registry. You should use it very carefully. The syntax is:

For example, to delete the key 'SOFTWARE\Test' from 'HKEY_LOCAL_MACHINE'.
EXEC master..xp_regdeletekey @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Test'

EXECUTE xp_regdeletevalue [@rootkey=]'rootkey', [@key=]'key', [@value_name=]'value_name'
This extended stored procedure will delete a particular value for a key in the registry. You should use it very carefully. The syntax is:

For example, to delete the value 'TestValue' for the key 'SOFTWARE\Test' from 'HKEY_LOCAL_MACHINE'
EXEC master..xp_regdeletevalue @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Test', @value_name='TestValue'

EXECUTE xp_regread [@rootkey=]'rootkey', [@key=]'key' [, [@value_name=]'value_name'] [, [@value=]@value OUTPUT]
This extended stored procedure is used to read from the registry. The syntax is:

For example, to read into the variable @test from the value 'TestValue' from the key 'SOFTWARE\Test' from the 'HKEY_LOCAL_MACHINE'
DECLARE @test varchar(20)EXEC master..xp_regread @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Test', @value_name='TestValue', @value=@test OUTPUTSELECT @test

EXECUTE xp_regwrite [@rootkey=]'rootkey', [@key=]'key', [@value_name=]'value_name', [@type=]'type', [@value=]'value'
This extended stored procedure is used to write to the registry. The syntax is:

For example, to write the variable 'Test' to the 'TestValue' value, key 'SOFTWARE\Test', 'HKEY_LOCAL_MACHINE'
EXEC master..xp_regwrite @rootkey='HKEY_LOCAL_MACHINE', @key='SOFTWARE\Test', @value_name='TestValue', @type='REG_SZ', @value='Test'