Archive for December, 2009
[EN] How to get a list of all DBCC commands in SQL Server 2008?
Dec 30th
Two years ago I wrote an article about undocumented DBCC commands in SQL Server 2005 for Polish Microsoft TechNet website (the article is in Polish). Yesterday I decided to check if I’m able to make a list of all DBCCs available on SQL Server 2008.
There are only about 30 DBCC commands described in SQL Server 2008 Books Online. Imagine that the full list contains 101 of them (and on SQL Server 2005 the number is even greater). Why Microsoft folks do not document so many commands (some of undocumented DBCCs are quite useful)? Honestly, I have no idea :-)
Fortunately, you can get the full list of DBCC commands easily and play with them on your own. Moreover, you can even get a syntax for each of those commands. So what should you do?
First of all you have to turn on the trace flag:
DBCC TRACEON(2588);
NOTE: On SQL Server 2005 and 2008 the flag number is 2588. On SQL Server 2000 the number is 2520.
Then you can get a full list of DBCCs by executing the following command:
DBCC HELP('?') WITH NO_INFOMSGS;
The result should be a list of all DBCC commands – both documented and undocumented.
NOTE: The DBCC HELP command can be used either to return a list of DBCC commands or to return a syntax of an individual command.
Now, save the result as a file (you can do it easily with SQL Server Management Studio by right-clicking in the Messages window and choosing Save Results As… option).
Assuming you saved the file to C:\dbcc.rpt (if not, change the path respectively in the code) you can use BULK INSERT statement to import the DBCC command names from the file into a temporary table:
IF OBJECT_ID('tempdb.dbo.#dbccs') IS NOT NULL DROP TABLE #dbccs; GO CREATE TABLE #dbccs( [dbcc] nvarchar(4000) NOT NULL); GO DECLARE @bulkcmd varchar(8000); SET @bulkcmd = 'BULK INSERT #dbccs FROM N''C:\dbcc.rpt'' WITH( ROWTERMINATOR = ''' + NCHAR(10) + NCHAR(13) + NCHAR(10) + ''', DATAFILETYPE = ''widechar'' )'; EXEC(@bulkcmd);
SELECT 'DBCC HELP(''' + [dbcc] + ''') WITH NO_INFOMSGS' FROM #dbccs ORDER BY [dbcc];
I’m attaching the script containing all the code from this post.
NOTE: Run any undocumented DBCC command at your own risk. Undocumented means unsupported so do not expect Microsoft (or me) to help you with any issue caused by running any unsupported piece of code on your SQL Server instances.
Attachments:
Undocumented DBCCs (T-SQL script)
DBCC commands on SQL Server 2008
[EN/PL] Resources
Dec 29th
[EN] How to check with T-SQL query if the TCP/IP protocol is enabled on SQL Server 2008 instance?
Dec 28th
Last week I was asked an interesting question: “How to check with T-SQL query if the TCP/IP protocol is enabled on a remote instance of SQL Server 2008 when you can’t use SQL Server Configuration Manager?”. The answer is pretty simple if you know that all the protocol settings are kept in the Windows registry on the server. And so, the query may look like:
DECLARE @key nvarchar(100); SELECT @key = 'SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\' + CASE @@SERVICENAME WHEN 'MSSQLSERVER' THEN 'MSSQLSERVER' ELSE 'MSSQL$' + @@SERVICENAME END + '\SuperSocketNetLib\Tcp'; DECLARE @test varchar(20); EXEC master.dbo.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE', @key = @key, @value_name = 'Enabled', @value = @test OUTPUT; SELECT CAST(@test AS binary(1));
If the result is binary 1, then the protocol is enabled. You can use regedit.exe to find out the paths to the keys in registry containing the settings for other protocols.
Also, you can check the static TCP port number using the same technique (I assumed the port is the same for all network interfaces):
DECLARE @key nvarchar(100); SELECT @key = 'SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL10.MSSQLSERVER\' + CASE @@SERVICENAME WHEN 'MSSQLSERVER' THEN 'MSSQLSERVER' ELSE 'MSSQL$' + @@SERVICENAME END + '\SuperSocketNetLib\Tcp\IpAll'; DECLARE @test varchar(20); EXEC master.dbo.xp_regread @rootkey = 'HKEY_LOCAL_MACHINE', @key = @key, @value_name = 'TcpPort', @value = @test OUTPUT; SELECT @test;
Furthermore, you can even enable any protocol using xp_regwrite extended stored procedure (see the article for details on the procedure). Remember that after you make any changes to the protocol settings the SQL Server service has to be restarted (probably the best way is to create a .bat/.cmd batch at the remote server that uses net start and net stop commands to restart the SQL Server instance).
If you think this is something ugly – to play with the registry within T-SQL query – remember that the SQL Server service account has full rights to the registry keys that contain the SQL Server settings.
[EN / PL] Let’s go!
Dec 28th
| Welcome to my new blog. All posts from the previous one will stay there at http://zine.net.pl/blogs/sqlgeek. And for now – Merry Christmas and a Happy New Year! | Witaj na moim nowym blogu. Wszystkie notki z poprzedniego bloga zostają pod adresem http://zine.net.pl/blogs/sqlgeek. A tymczasem – Wesołych Świąt i Szczęśliwego Nowego Roku! |
[PL] PS. Przepraszam wszystkich, którym wyciąłem komentarze do tej notki. Musiałem niestety przeinstalować silnik WordPress :-)

Nazywam się Paweł Potasiński i pracuję w polskim oddziale Microsoft w dziale Small and Midmarket Solutions & Partners (SMS&P) jako Partner Technology Advisor.




