<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3747367966787685868</id><updated>2012-01-26T13:21:26.246-08:00</updated><title type='text'>OnePlace4SQL</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>19</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-8283074641836866534</id><published>2008-09-01T03:32:00.000-07:00</published><updated>2008-09-01T03:37:46.309-07:00</updated><title type='text'>Total Harddisk space</title><content type='html'>Thanks to Uri Dimant who posted this code in Microsoft sql server newsgroup. I am posting this in my blog just for future reference&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;CREATE PROCEDURE sp_totalHDDspace&lt;br /&gt;AS&lt;br /&gt;SET NOCOUNT ON&lt;br /&gt;&lt;br /&gt;DECLARE @hr int&lt;br /&gt;DECLARE @fso int&lt;br /&gt;DECLARE @drive char(1)&lt;br /&gt;DECLARE @odrive int&lt;br /&gt;DECLARE @TotalSize varchar(20)&lt;br /&gt;DECLARE @MB bigint ; SET @MB = 1048576&lt;br /&gt;&lt;br /&gt;CREATE TABLE #drives (drive char(1) PRIMARY KEY,&lt;br /&gt;FreeSpace int NULL,&lt;br /&gt;TotalSize int NULL)&lt;br /&gt;&lt;br /&gt;INSERT #drives(drive,FreeSpace)&lt;br /&gt;EXEC master.dbo.xp_fixeddrives&lt;br /&gt;&lt;br /&gt;EXEC @hr=sp_OACreate 'Scripting.FileSystemObject',@fso OUT&lt;br /&gt;IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso&lt;br /&gt;&lt;br /&gt;DECLARE dcur CURSOR LOCAL FAST_FORWARD&lt;br /&gt;FOR SELECT drive from #drives&lt;br /&gt;ORDER by drive&lt;br /&gt;&lt;br /&gt;OPEN dcur&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM dcur INTO @drive&lt;br /&gt;&lt;br /&gt;WHILE @@FETCH_STATUS=0&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;EXEC @hr = sp_OAMethod @fso,'GetDrive', @odrive OUT, @drive&lt;br /&gt;IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso&lt;br /&gt;&lt;br /&gt;EXEC @hr = sp_OAGetProperty @odrive,'TotalSize', @TotalSize OUT&lt;br /&gt;IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @odrive&lt;br /&gt;&lt;br /&gt;UPDATE #drives&lt;br /&gt;SET TotalSize=@TotalSize/@MB&lt;br /&gt;WHERE drive=@drive&lt;br /&gt;&lt;br /&gt;FETCH NEXT FROM dcur INTO @drive&lt;br /&gt;&lt;br /&gt;END&lt;br /&gt;&lt;br /&gt;CLOSE dcur&lt;br /&gt;DEALLOCATE dcur&lt;br /&gt;&lt;br /&gt;EXEC @hr=sp_OADestroy @fso&lt;br /&gt;IF @hr &lt;&gt; 0 EXEC sp_OAGetErrorInfo @fso&lt;br /&gt;&lt;br /&gt;SELECT drive,&lt;br /&gt;FreeSpace as 'Free(MB)',&lt;br /&gt;TotalSize as 'Total(MB)',&lt;br /&gt;CAST((FreeSpace/(TotalSize*1.0))*100.0 as int) as 'Free(%)'&lt;br /&gt;FROM #drives&lt;br /&gt;ORDER BY drive&lt;br /&gt;&lt;br /&gt;DROP TABLE #drives&lt;br /&gt;&lt;br /&gt;RETURN&lt;br /&gt;go&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-8283074641836866534?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/8283074641836866534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=8283074641836866534' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8283074641836866534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8283074641836866534'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2008/09/total-harddisk-space.html' title='Total Harddisk space'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-5587186356694307929</id><published>2008-08-06T01:27:00.000-07:00</published><updated>2008-08-06T01:38:51.524-07:00</updated><title type='text'>Code to Identify the user and date stored procedure modified</title><content type='html'>I have come across so many posting in Microsoft SQL Server newsgroup asking for how to identify the user and date a stored procedure was modified. Unfortunately SQL 2000 does not record when a stored procedure is modified, unless it is dropped and recreated. Fortunately SQL 2005 does have this feature. Use the following code to identify the user and the date that the stored procedure was modified&lt;br /&gt;&lt;br /&gt;select name,modify_date from sys.procedures&lt;br /&gt;order by modify_date desc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-5587186356694307929?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/5587186356694307929/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=5587186356694307929' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5587186356694307929'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5587186356694307929'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2008/08/code-to-identify-user-and-date-stored.html' title='Code to Identify the user and date stored procedure modified'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-985305671421000982</id><published>2008-07-23T08:02:00.001-07:00</published><updated>2008-07-23T08:02:32.144-07:00</updated><title type='text'>Rebuild the log</title><content type='html'>1. From a query window, set the status so that you can update the system tables by running the following query:&lt;br /&gt;&lt;br /&gt;use Master&lt;br /&gt;go&lt;br /&gt;sp_configure " allow updates", 1&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;reconfigure with override&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;2. Then set the status of the DB that is giving you the problem (XXXXX) into &lt;br /&gt;Emergency Mode by running the following query:&lt;br /&gt;&lt;br /&gt;update sysdatabases set status = 32768 where name = '&lt;DBName&gt;'&lt;br /&gt;go&lt;br /&gt;checkpoint&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;shutdown with nowait&lt;br /&gt;go&lt;br /&gt;&lt;br /&gt;3. Go into the data directory e.g. (MSSQL\DATA) and rename the log file associated the DB in question (XXXX.ldf) to some temporary name, such as XXXX.TMP.&lt;br /&gt;&lt;br /&gt;4. Exit the query window.&lt;br /&gt;&lt;br /&gt;5. Then start up SQL Server from a DOS command window by issuing: &lt;br /&gt;&lt;br /&gt;sqlservr -c -T3608 -T4022.&lt;br /&gt;&lt;br /&gt;6. Bring up another query window and verify that the DB is in emergency mode by issuing:&lt;br /&gt;&lt;br /&gt;Select Name, Status from Sysdatabases where name = '&lt;DB_Name&gt;'&lt;br /&gt;&lt;br /&gt;7. Verify that the status is 32768. If it is, then issue the query:&lt;br /&gt;&lt;br /&gt;dbcc traceon(3604)&lt;br /&gt;dbcc rebuild_log('&lt;DB_Name&gt;','&lt;log_filename&gt;') &lt;--- You will need the quotation &lt;br /&gt;marks &lt;br /&gt;&lt;br /&gt;REBUILD_LOG should take less than 5 minutes even on a very large database. It should complete with the message DBCC execution completed&lt;br /&gt;&lt;br /&gt;8. Take the database out of bypass recovery mode by issuing the command&lt;br /&gt;update sysdatabases set status = 0 where name = '&lt;DBName&gt;'&lt;br /&gt;&lt;br /&gt;9. Exit the query window and then shutdown (Ctrl-C in the DOS window) and restart SQL server. Verify the status of the database by running DBCC CHECKDB on the database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-985305671421000982?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/985305671421000982/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=985305671421000982' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/985305671421000982'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/985305671421000982'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2008/07/rebuild-log.html' title='Rebuild the log'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-8372238056919609331</id><published>2008-07-23T05:40:00.000-07:00</published><updated>2008-07-23T05:42:05.272-07:00</updated><title type='text'>Identifying SQL Server/Agent start up account using T-SQL</title><content type='html'>--SQL Serer&lt;br /&gt;DECLARE @test varchar(20)&lt;br /&gt;&lt;br /&gt;EXEC master..xp_regread&lt;br /&gt;@rootkey='HKEY_LOCAL_MACHINE',@key='SYSTEM\CurrentControlSet\Services\MSSQLSERVER',&lt;br /&gt;@value_name='ObjectName',&lt;br /&gt;@value=@test OUTPUT&lt;br /&gt;&lt;br /&gt;SELECT @test&lt;br /&gt;&lt;br /&gt;--Agent&lt;br /&gt;&lt;br /&gt;DECLARE @test varchar(20)&lt;br /&gt;EXEC master..xp_regread&lt;br /&gt;@rootkey='HKEY_LOCAL_MACHINE',&lt;br /&gt;@key='SYSTEM\CurrentControlSet\Services\SQLSERVERAGENT',@value_name='ObjectName',&lt;br /&gt;@value=@test OUTPUT&lt;br /&gt;&lt;br /&gt;SELECT @test&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-8372238056919609331?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/8372238056919609331/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=8372238056919609331' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8372238056919609331'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8372238056919609331'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2008/07/identifying-sql-serveragent-start-up.html' title='Identifying SQL Server/Agent start up account using T-SQL'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-2431913500031940583</id><published>2008-06-09T06:21:00.000-07:00</published><updated>2008-06-09T06:26:58.670-07:00</updated><title type='text'>SQL 2005 - Word Search</title><content type='html'>There are many occasions were we need to search for a word that a stored procedure might be using. The code bellow shows all the stored procedure that contain the word "CallId"&lt;br /&gt;&lt;br /&gt;    SELECT Name&lt;br /&gt;    FROM sys.procedures&lt;br /&gt;    WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%CallId%'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-2431913500031940583?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/2431913500031940583/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=2431913500031940583' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/2431913500031940583'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/2431913500031940583'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2008/06/sql-2005-word-search.html' title='SQL 2005 - Word Search'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-5608096291981172577</id><published>2007-06-12T15:40:00.000-07:00</published><updated>2007-06-12T15:42:47.900-07:00</updated><title type='text'>Comma delimited string to table</title><content type='html'>CREATE FUNCTION [dbo].[ufn_CSVToTable] ( @StringInput VARCHAR(8000) )&lt;br /&gt;RETURNS @OutputTable TABLE ( [String] VARCHAR(10) )&lt;br /&gt;AS&lt;br /&gt;BEGIN&lt;br /&gt;&lt;br /&gt;    DECLARE @String    VARCHAR(10)&lt;br /&gt;&lt;br /&gt;    WHILE LEN(@StringInput) &gt; 0&lt;br /&gt;    BEGIN&lt;br /&gt;        SET @String      = LEFT(@StringInput, &lt;br /&gt;                                ISNULL(NULLIF(CHARINDEX(',', @StringInput) - 1, -1),&lt;br /&gt;                                LEN(@StringInput)))&lt;br /&gt;        SET @StringInput = SUBSTRING(@StringInput,&lt;br /&gt;                                     ISNULL(NULLIF(CHARINDEX(',', @StringInput), 0),&lt;br /&gt;                                     LEN(@StringInput)) + 1, LEN(@StringInput))&lt;br /&gt;&lt;br /&gt;        INSERT INTO @OutputTable ( [String] )&lt;br /&gt;        VALUES ( @String )&lt;br /&gt;    END&lt;br /&gt;    &lt;br /&gt;    RETURN&lt;br /&gt;END&lt;br /&gt;GO&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-5608096291981172577?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/5608096291981172577/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=5608096291981172577' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5608096291981172577'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5608096291981172577'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/06/comma-delimited-string-to-table.html' title='Comma delimited string to table'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-6632597348335187682</id><published>2007-06-11T16:00:00.000-07:00</published><updated>2007-06-11T16:11:53.480-07:00</updated><title type='text'>SQL Server performance counters are missing in Windows 64bit</title><content type='html'>When you run the PERFMON on a 64 bit windows server you are actually running the 64bit version of  the application which can only load 64bit counters, but not counters for a local 32-bit applications. To workaround the problem, launch the application using /32 switch, like this mmc /32 perfmon.msc&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-6632597348335187682?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/6632597348335187682/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=6632597348335187682' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/6632597348335187682'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/6632597348335187682'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/06/sql-server-performance-counters-are.html' title='SQL Server performance counters are missing in Windows 64bit'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-8265422167485894448</id><published>2007-06-07T08:35:00.000-07:00</published><updated>2007-06-07T08:37:07.905-07:00</updated><title type='text'>Which action fired the trigger?</title><content type='html'>Using the following logic you can identify which action cased the trigger to fire&lt;br /&gt;&lt;br /&gt;if exists (select 1 from deleted) and exists (select 1 from inserted)&lt;br /&gt; print ‘Update’&lt;br /&gt;&lt;br /&gt;if exists (select 1 from inserted) and not exists (select 1 from deleted)&lt;br /&gt; print ‘Insert’&lt;br /&gt;&lt;br /&gt;if exists (select 1 from deleted) and not exists (select 1 from inserted)&lt;br /&gt; print ‘Delete’&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-8265422167485894448?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/8265422167485894448/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=8265422167485894448' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8265422167485894448'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8265422167485894448'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/06/which-action-fired-trigger.html' title='Which action fired the trigger?'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-3890566000801801024</id><published>2007-06-05T14:02:00.000-07:00</published><updated>2007-06-05T14:03:06.438-07:00</updated><title type='text'>Display trigger status</title><content type='html'>--version sql server 2000&lt;br /&gt;&lt;br /&gt;SELECT&lt;br /&gt;         name,&lt;br /&gt;         status = CASE WHEN OBJECTPROPERTY (id, 'ExecIsTriggerDisabled') = 0&lt;br /&gt;            THEN 'Enabled' ELSE 'Disabled' END,&lt;br /&gt;         owner = OBJECT_NAME (parent_obj)&lt;br /&gt;FROM&lt;br /&gt;         sysobjects&lt;br /&gt;WHERE&lt;br /&gt;         type = 'TR'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-3890566000801801024?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/3890566000801801024/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=3890566000801801024' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/3890566000801801024'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/3890566000801801024'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/06/display-trigger-status.html' title='Display trigger status'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-5913311591787880066</id><published>2007-05-29T03:42:00.000-07:00</published><updated>2007-05-30T03:20:13.203-07:00</updated><title type='text'>Rotate a table in SQL Server</title><content type='html'>&lt;strong&gt;Rows to Column&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Source Table&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;Year|Quarter|Amount&lt;br /&gt;========================&lt;br /&gt;1995|1      |125,000.90&lt;br /&gt;1995|2      |136,000.75&lt;br /&gt;1995|3      |212,000.34&lt;br /&gt;1995|4      |328,000.82&lt;br /&gt;1996|3      |728,000.35&lt;br /&gt;1996|2      |422,000.13&lt;br /&gt;1996|1      |328,000.82&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Result Table&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;    YEAR   |     Q1     |         Q2     |         Q3    |         Q4&lt;br /&gt;   -------------------------------------------------------------------&lt;br /&gt;   1995    | 125,000.90 |     136,000.75 |     212,000.34|      328,000.82&lt;br /&gt;   1996    | 328,000.82 |     422,000.13 |     728,000.35|            0.00&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;SQL&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;SELECT year=q.year,&lt;br /&gt;SUM(CASE quarter WHEN 1 THEN amount ELSE 0 END) as Q1,&lt;br /&gt;SUM(CASE quarter WHEN 2 THEN amount ELSE 0 END) as Q2,&lt;br /&gt;SUM(CASE quarter WHEN 3 THEN amount ELSE 0 END) as Q3,&lt;br /&gt;SUM(CASE quarter WHEN 4 THEN amount ELSE 0 END) as Q4&lt;br /&gt;FROM qtrsales q&lt;br /&gt;GROUP BY year&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Columns to Row&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;&lt;em&gt;Source Table&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;ID    | RefDate  |Rcvd Date&lt;br /&gt;----------------------------&lt;br /&gt;1     |  01/01/04|  02/01/04&lt;br /&gt;2     |  05/01/04|  07/01/04&lt;br /&gt;3     |  07/01/04|  12/01/04&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;Result Table&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;ID    | Date     | Type&lt;br /&gt;----------------------------&lt;br /&gt;1     |  01/01/04|   RefDate&lt;br /&gt;1     |  02/01/04|   RcvdDate&lt;br /&gt;2     |  05/01/04|   RefDate&lt;br /&gt;2     |  07/01/04|   RcvdDate&lt;br /&gt;3     |  07/01/04|   RefDate&lt;br /&gt;3     |  12/01/04|   RcvdDate&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;SQL&lt;/strong&gt;&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;SELECT ID, RefDate, 'RefDate' AS Type FROM myTable&lt;br /&gt;UNION &lt;br /&gt;SELECT ID, RcvdDate, 'RcvdDate' AS Type FROM myTable&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-5913311591787880066?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/5913311591787880066/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=5913311591787880066' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5913311591787880066'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/5913311591787880066'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/rotate-table-in-sql-server.html' title='Rotate a table in SQL Server'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-8802948261240681655</id><published>2007-05-22T14:50:00.000-07:00</published><updated>2007-05-22T14:51:49.034-07:00</updated><title type='text'>How to transfer database diagrams to a different database</title><content type='html'>Database diagrams are stored in the 'dtproperties' table within the database. So, database diagrams can be transferred to a different database, by transferring the contents of this table.&lt;br /&gt;&lt;br /&gt;For example , run the following query to transfer the diagram named 'MyTableDesign' from 'pubs' database to 'northwind':&lt;br /&gt;&lt;br /&gt;INSERT northwind..dtproperties&lt;br /&gt;SELECT objectid, property, value, lvalue, version&lt;br /&gt;FROM pubs..dtproperties&lt;br /&gt;WHERE objectid = &lt;br /&gt;(&lt;br /&gt;SELECT objectid&lt;br /&gt;FROM pubs..dtproperties&lt;br /&gt;WHERE value='MyTableDesign'&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;Make sure, the tables referenced by these diagrams already exist in the target database, or else these diagrams won't show up in the target database.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-8802948261240681655?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/8802948261240681655/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=8802948261240681655' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8802948261240681655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8802948261240681655'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/how-to-transfer-database-diagrams-to.html' title='How to transfer database diagrams to a different database'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-8745433183363508223</id><published>2007-05-22T01:42:00.001-07:00</published><updated>2007-05-22T01:46:22.184-07:00</updated><title type='text'>Moving SQL Server 2000 databases to another machine</title><content type='html'>1.Detach all user databasese from source server&lt;br /&gt;2.Stop SQL Server service on the source server&lt;br /&gt;3.Copy the master, msdb and model database to the destination server&lt;br /&gt;&lt;br /&gt;Attaching MSDB database on to destination server&lt;br /&gt;&lt;br /&gt;To attach the MSDB database, you must startt SQL Server together with the -c option, the -m option, and trace flag 3608. Trace flag 3608 prevents SQL Server from recovering any database except the master database. To add the -c option, the -m option, and trace flag 3608, follow the steps in the "Moving the model database" section. After you add the -c option, the -m option and trace flag 3608, follow these steps: &lt;br /&gt;1. Stop, and then restart SQL Server. &lt;br /&gt;2. Make sure that the SQL Server Agent service is not currently running. &lt;br /&gt;&lt;br /&gt;3. Detach the msdb database as follows:&lt;br /&gt; use master&lt;br /&gt; go&lt;br /&gt; sp_detach_db 'msdb'&lt;br /&gt; go&lt;br /&gt;4. Move the Msdbdata.mdf and Msdblog.ldf files from the current location (D:\Mssql8\Data) to the new location (E:\Mssql8\Data). &lt;br /&gt;5. Remove -c -m -T3608 from the startup parameters box in Enterprise Manager. &lt;br /&gt;6. Stop and then restart SQL Server.&lt;br /&gt;7. Reattach the msdb database as follows:&lt;br /&gt; use master&lt;br /&gt; go &lt;br /&gt; sp_attach_db 'msdb','E:\Mssql8\Data\msdbdata.mdf','E:\Mssql8\Data\msdblog.ldf' &lt;br /&gt; go&lt;br /&gt;&lt;br /&gt;attaching the master database on to destination server&lt;br /&gt;&lt;br /&gt;1. Change the path for the master data files and the master log files in SQL Server Enterprise Manager.&lt;br /&gt;&lt;br /&gt;Note You may also change the location of the error log here. &lt;br /&gt;2. Right-click the SQL Server in Enterprise Manager and then click Properties. &lt;br /&gt;3. Click Startup Parameters to see the following entries:&lt;br /&gt; -dD:\MSSQL7\data\master.mdf&lt;br /&gt;    -eD:\MSSQL7\log\ErrorLog&lt;br /&gt;    -lD:\MSSQL7\data\mastlog.ldf&lt;br /&gt;  -d is the fully qualified path for the master database data file.&lt;br /&gt;&lt;br /&gt;  -e is the fully qualified path for the error log file.&lt;br /&gt;&lt;br /&gt;  -l is the fully qualified path for the master database log file. &lt;br /&gt;4. Change these values as follows: &lt;br /&gt; a.  Remove the current entries for the Master.mdf and Mastlog.ldf files. &lt;br /&gt; b.  Add new entries specifying the new location:&lt;br /&gt; -dE:\SQLDATA\master.mdf&lt;br /&gt;      -lE:\SQLDATA\mastlog.ldf&lt;br /&gt; &lt;br /&gt; &lt;br /&gt;5. Stop SQL Server. &lt;br /&gt;6. Copy the Master.mdf and Mastlog.ldf files to the new location (E:\Sqldata). &lt;br /&gt;7. Restart SQL Server &lt;br /&gt;&lt;br /&gt;Moving Temp database&lt;br /&gt;You can move tempdb files by using the ALTER DATABASE statement. &lt;br /&gt;&lt;br /&gt;1. Use the ALTER DATABASE statement, specifying the logical file name as follows:use master&lt;br /&gt; go&lt;br /&gt; Alter database tempdb modify file (name = tempdev, filename = 'E:\Sqldata\tempdb.mdf')&lt;br /&gt; go&lt;br /&gt; Alter database tempdb modify file (name = templog, filename = 'E:\Sqldata\templog.ldf')&lt;br /&gt; go&lt;br /&gt;2. Stop and then restart SQL Server.&lt;br /&gt;&lt;br /&gt;Attaching User database&lt;br /&gt;1. use exec sp_attach_db&lt;br /&gt;    use master&lt;br /&gt;    go&lt;br /&gt;    EXEC sp_attach_db @dbname = N'pubs', &lt;br /&gt;    @filename1 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs.mdf', &lt;br /&gt;    @filename2 = N'c:\Program Files\Microsoft SQL Server\MSSQL\Data\pubs_log.ldf'&lt;br /&gt;    go&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-8745433183363508223?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/8745433183363508223/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=8745433183363508223' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8745433183363508223'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/8745433183363508223'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/moving-sql-server-2000-databases-to.html' title='Moving SQL Server 2000 databases to another machine'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-621743199487305459</id><published>2007-05-21T04:26:00.000-07:00</published><updated>2007-05-21T04:27:30.343-07:00</updated><title type='text'>To enable SQL Authentication for the default instance using T-SQL</title><content type='html'>EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft&lt;br /&gt;\MSSQLServer\MSSQLServer', N'LoginMode', REG_DWORD, 2&lt;br /&gt;&lt;br /&gt;or for a named instance:&lt;br /&gt;&lt;br /&gt;EXEC xp_instance_regwrite N'HKEY_LOCAL_MACHINE', N'Software\Microsoft&lt;br /&gt;\Microsoft SQL Server\&lt;Instance Name&gt;\MSSQLServer\', N'LoginMode',&lt;br /&gt;REG_DWORD, 2&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-621743199487305459?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/621743199487305459/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=621743199487305459' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/621743199487305459'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/621743199487305459'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/to-enable-sql-authentication-for_21.html' title='To enable SQL Authentication for the default instance using T-SQL'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-4219359314472628534</id><published>2007-05-18T06:12:00.000-07:00</published><updated>2007-05-18T06:16:47.602-07:00</updated><title type='text'>Selecting Nth row from SQL Server 2000 table</title><content type='html'>Scritpt bellow explain how to get Nth row from SQL Server 2000 table&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;SELECT * FROM &lt;br /&gt;(&lt;br /&gt; SELECT *, (SELECT COUNT(*) FROM MyTable t2 WHERE t2.ID&lt;=t1.ID) rn FROM MyTable t1&lt;br /&gt;) x WHERE rn%5=1&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;where 5 is the column number&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-4219359314472628534?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/4219359314472628534/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=4219359314472628534' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/4219359314472628534'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/4219359314472628534'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/selecting-nth-row-from-sql-server-2000.html' title='Selecting Nth row from SQL Server 2000 table'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-4481575786246524245</id><published>2007-05-18T01:43:00.000-07:00</published><updated>2007-05-18T01:45:00.437-07:00</updated><title type='text'>Top 20 large tables</title><content type='html'>--sql 2000&lt;br /&gt;&lt;br /&gt;declare @topcount int &lt;br /&gt;set @topcount = 20&lt;br /&gt;&lt;br /&gt;declare @pagesize bigint&lt;br /&gt;declare @dbid int&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select @pagesize = low &lt;br /&gt;from master.dbo.spt_values&lt;br /&gt;where number = 1&lt;br /&gt;and type = 'E'&lt;br /&gt;&lt;br /&gt;declare @spt_space table&lt;br /&gt; (&lt;br /&gt; objid int null,&lt;br /&gt; rows int null,&lt;br /&gt; reserved int null,&lt;br /&gt; data int null,&lt;br /&gt; indexp int null,&lt;br /&gt; unused int null&lt;br /&gt; )&lt;br /&gt;&lt;br /&gt;insert into @spt_space&lt;br /&gt;select objid = id, &lt;br /&gt; rows = sum(case when indid in (0, 1) then rowcnt else 0 end),&lt;br /&gt; reserved = sum(case when indid in (0, 1, 255)&lt;br /&gt;   then reserved&lt;br /&gt;   else 0&lt;br /&gt;   end) * @pagesize / 1024 /1024,&lt;br /&gt; data = sum(case when indid in (0, 1) then dpages&lt;br /&gt;   when indid = 255 then used&lt;br /&gt;   else 0&lt;br /&gt;   end) * @pagesize / 1024/1024,&lt;br /&gt; indexp = sum(case when indid in (0, 1, 255)&lt;br /&gt;   then used&lt;br /&gt;   else 0&lt;br /&gt;   end) * @pagesize / 1024/1024,&lt;br /&gt; unused = sum(case when indid in (0, 1, 255)&lt;br /&gt;   then used&lt;br /&gt;   else 0&lt;br /&gt;   end) * @pagesize / 1024/1024&lt;br /&gt;from sysindexes&lt;br /&gt;where rowcnt &gt; 0&lt;br /&gt;group&lt;br /&gt;by id, indid&lt;br /&gt;order &lt;br /&gt;by reserved desc&lt;br /&gt;&lt;br /&gt;set rowcount @topcount&lt;br /&gt;select Table_Name = name,&lt;br /&gt; rows,&lt;br /&gt; reserved_MB = ltrim(str(reserved,15,0) + ' ' + 'MB'),&lt;br /&gt; data_MB = ltrim(str(data,15,0) + ' ' + 'MB'),&lt;br /&gt; index_size_MB = ltrim(str(indexp - data,15,0) + ' ' + 'MB'),&lt;br /&gt; unused_MB = ltrim(str(reserved - unused,15,0) + ' ' + 'MB'),&lt;br /&gt; idx_data_ratio = ltrim(str((indexp - data)*100 /data) + '%'),&lt;br /&gt; unused_pct = ltrim(str((reserved - unused) * 100 /reserved) + '%')&lt;br /&gt;from @spt_space s join sysobjects o on o.id = s.objid and xtype = 'U'&lt;br /&gt;where data &gt; 0&lt;br /&gt;order &lt;br /&gt;by reserved desc&lt;br /&gt;set rowcount 0&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-4481575786246524245?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/4481575786246524245/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=4481575786246524245' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/4481575786246524245'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/4481575786246524245'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/top-20-large-tables.html' title='Top 20 large tables'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-282641601248946187</id><published>2007-05-16T03:02:00.001-07:00</published><updated>2007-05-16T03:02:47.717-07:00</updated><title type='text'>Blocking information</title><content type='html'>SELECT datediff(mi,last_batch,getdate())LockTime,P.SPID, P.BLOCKED BLOCKEDBY, RTRIM(P.HOSTNAME) HOSTNAME,sql_handle &lt;br /&gt;FROM MASTER..SYSPROCESSES P &lt;br /&gt;WHERE P.BLOCKED &lt;&gt; 0&lt;br /&gt;AND SPID&lt;&gt;BLOCKED&lt;br /&gt;OR SPID IN (SELECT BLOCKED FROM MASTER..SYSPROCESSES)&lt;br /&gt;AND BLOCKED IN (SELECT SPID FROM MASTER..SYSPROCESSES)&lt;br /&gt;AND BLOCKED=0&lt;br /&gt;ORDER BY P.BLOCKED, P.SPID&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-282641601248946187?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/282641601248946187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=282641601248946187' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/282641601248946187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/282641601248946187'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/blocking-information.html' title='Blocking information'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-2409184432434028946</id><published>2007-05-16T02:09:00.000-07:00</published><updated>2007-05-16T02:13:31.585-07:00</updated><title type='text'>Identifying log running/cpu intensive SQL query using Performance Monitor</title><content type='html'>Identifying log running/cpu intensive SQL query using Performance Monitor &lt;br /&gt;&lt;br /&gt;This article describe how to identify a log running sql script using Performance Monitor tool&lt;br /&gt;1. Launch the System Performance tool from, Administrative tools-&gt; Performance&lt;br /&gt;2. Select Thread  from Performance Object drop down box&lt;br /&gt;3. Select % Processor time and ID Thread from counter list box&lt;br /&gt;4. Select all sqlsrv instance from instance list and click add button&lt;br /&gt;5. Change the view style to report form&lt;br /&gt;&lt;br /&gt;You can identify the long running/cpu intensive SQL Server thread by watching the % process time column. &lt;br /&gt;To get the SQL statement that it currently executing use &lt;br /&gt;&lt;br /&gt;DECLARE @Handle binary(20)&lt;br /&gt;SELECT @Handle = sql_handle FROM sysprocesses WHERE kpid = 1000--(replace it with the ID Thread value)&lt;br /&gt;SELECT * FROM ::fn_get_sql(@Handle)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-2409184432434028946?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/2409184432434028946/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=2409184432434028946' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/2409184432434028946'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/2409184432434028946'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/identifying-log-runningcpu-intensive.html' title='Identifying log running/cpu intensive SQL query using Performance Monitor'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-1260261439769749881</id><published>2007-05-15T04:01:00.000-07:00</published><updated>2007-05-15T04:02:48.890-07:00</updated><title type='text'>Starting/Stoping SQL Server service on remote machine</title><content type='html'>sc [ServerName] Command ServiceName [ServiceArguments]&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ServerName&lt;/strong&gt;&lt;br /&gt;Specifies the name of the server where the service will be started or stopped. Enter the ServerName in UNC format .&lt;br /&gt;ServerName is not needed if you are stopping/starting a local service.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Command&lt;/strong&gt;&lt;br /&gt;The command is either “start” or “stop”.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ServiceName &lt;/strong&gt;&lt;br /&gt;The service name to be started or stopped.&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;ServiceArguments&lt;/strong&gt; &lt;br /&gt;Specifies service arguments to pass to the service being started.&lt;br /&gt;&lt;br /&gt;Note: this option is not used when the command “stop” is issued.&lt;br /&gt;For more information see http://www.databasejournal.com/features/mssql/article.php/3644906&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-1260261439769749881?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/1260261439769749881/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=1260261439769749881' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/1260261439769749881'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/1260261439769749881'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/startingstoping-sql-server-service-on.html' title='Starting/Stoping SQL Server service on remote machine'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3747367966787685868.post-1063885919064252633</id><published>2007-05-14T08:18:00.000-07:00</published><updated>2007-05-16T01:36:18.828-07:00</updated><title type='text'>Script to find out specific word in database</title><content type='html'>DECLARE @SSQL VARCHAR(200)&lt;br /&gt; SELECT @COLUMN = '%' + @COLUMN + '%'&lt;br /&gt; &lt;br /&gt;&lt;br /&gt;&lt;br /&gt; SET NOCOUNT ON&lt;br /&gt; &lt;br /&gt; SELECT  @SSQL = 'TABLES THAT CONTAIN COLUMNS THAT BEGIN WITH ' + @COLUMN&lt;br /&gt; SELECT  @SSQL&lt;br /&gt; PRINT  '----------------------------------------------------------'&lt;br /&gt; SELECT  CONVERT(VARCHAR(60), O.NAME) "TABLE NAME" &lt;br /&gt; FROM  SYSCOLUMNS C, SYSOBJECTS O, MASTER.DBO.SYSTYPES T &lt;br /&gt; WHERE  C.ID = O.ID AND C.XTYPE = T.XTYPE&lt;br /&gt; AND  C.NAME LIKE @COLUMN&lt;br /&gt; AND  O.TYPE = 'U'&lt;br /&gt; GROUP BY O.NAME&lt;br /&gt; &lt;br /&gt; /*FOR STORED PROCEDURES, ADD WILDCARD TO BEGINNING BECAUSE COLUMN WILL BE  CONTAINED WITHIN TEXT*/&lt;br /&gt; SELECT  @COLUMN =  '%' + @COLUMN &lt;br /&gt; &lt;br /&gt; SELECT  @SSQL = 'PROCS THAT CONTAIN THE WORD ' + REPLACE(@COLUMN, '%', '')&lt;br /&gt; SELECT  @SSQL&lt;br /&gt; PRINT  '----------------------------------------------------------'&lt;br /&gt; SELECT  CONVERT(VARCHAR(60), O.NAME) "NAME",&lt;br /&gt; CASE WHEN O.XTYPE='P' THEN 'STORED PROCEDURE'&lt;br /&gt;      WHEN O.XTYPE='TR' THEN 'TRIGGER'&lt;br /&gt;      WHEN O.XTYPE='V' THEN 'VIEW'&lt;br /&gt;      WHEN O.XTYPE='FN' THEN 'FUNCTION'&lt;br /&gt; END [OBJECT TYPE]&lt;br /&gt; FROM  SYSOBJECTS O, SYSCOMMENTS C&lt;br /&gt; WHERE  O.ID = C.ID&lt;br /&gt; AND  C.TEXT LIKE @COLUMN&lt;br /&gt; &lt;br /&gt; SET NOCOUNT OFF&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3747367966787685868-1063885919064252633?l=oneplace4sql.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://oneplace4sql.blogspot.com/feeds/1063885919064252633/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=3747367966787685868&amp;postID=1063885919064252633' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/1063885919064252633'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3747367966787685868/posts/default/1063885919064252633'/><link rel='alternate' type='text/html' href='http://oneplace4sql.blogspot.com/2007/05/script-to-find-out-specific-word-in.html' title='Script to find out specific word in database'/><author><name>OnePlace4SQL</name><uri>http://www.blogger.com/profile/16724502419468007363</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
