Skip to content

Instantly share code, notes, and snippets.

-- Note: querying sys.dm_os_buffer_descriptors
-- requires the VIEW_SERVER_STATE permission.
DECLARE @total_buffer INT;
SELECT @total_buffer = cntr_value
FROM sys.dm_os_performance_counters
WHERE RTRIM([object_name]) LIKE '%Buffer Manager'
AND counter_name = 'Total Pages';
@jdaigle
jdaigle / gist:5459155
Created April 25, 2013 11:45
"How To Obtain The Size Of All Tables In A SQL Server Database (see http://therightstuff.de/CommentView,guid,df930155-f60f-4f56-ab33-f1352ff091a1.aspx)
SET NOCOUNT ON
DBCC UPDATEUSAGE(0)
-- DB size.
EXEC sp_spaceused
-- Table row counts and sizes.
CREATE TABLE #t
(
@jdaigle
jdaigle / gist:5428198
Created April 21, 2013 02:19
query for single use ad hoc queries in the plan cache
SELECT [text], cp.size_in_bytes, plan_handle
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_sql_text(plan_handle)
WHERE
cp.cacheobjtype = N'Compiled Plan'
AND cp.objtype = N'Adhoc'
AND cp.usecounts = 1
ORDER BY cp.size_in_bytes DESC;
@jdaigle
jdaigle / gist:4631728
Created January 25, 2013 04:23
playing around with SQL Server XML data type - i might create a lightweight document database derived from this
--insert into Documents VALUES ('products/1', '<product><name>Foo</name></product>', 'dynamic');
--insert into Documents VALUES ('products/2', '<product><name>Bar</name></product>', 'dynamic');
--insert into Documents VALUES ('products/3', '<product><name>Fizz</name></product>', 'dynamic');
--insert into Documents VALUES ('products/4', '<product><name>Buzz</name></product>', 'dynamic');
UPDATE Documents SET Data = '<product><name>Foo</name></product>', entitytype='dynamic' WHERE Id = 'products/1';
select Data.value('(//product/name)[1]','varchar(30)') from Documents where entitytype = 'dynamic2'
select Data.value('(//product/name)[1]','varchar(30)') from Documents
select Data.value('(//product/name)[1]','varchar(max)') from Documents
var name = "John Doe";
function getFirstName(fullName) {
var next = fullName[0];
var i = 0;
var length = fullName.length;
while (i < length && next !== " ") {
console.log(fullName[i]);
i++;
next = fullName[i];
@jdaigle
jdaigle / gist:2781464
Created May 24, 2012 13:09
SQL Server Service Broker: Query to get estimated number of rows in queues
SELECT q.name, p.rows
FROM sys.partitions p
INNER JOIN sys.internal_tables t ON t.object_id = p.object_id
INNER JOIN sys.service_queues q ON q.object_id = t.parent_object_id
WHERE p.index_id IN (1, 0) --AND q.name = 'QueueName'
@jdaigle
jdaigle / gist:2781349
Created May 24, 2012 12:39
SQL Server Service Broker: Short Script to clear empty a named queue
DECLARE @handle UNIQUEIDENTIFIER;
WHILE (SELECT COUNT(*) FROM NameOfQueue) > 0
BEGIN
RECEIVE TOP (1) @handle = conversation_handle FROM NameOfQueue;
END CONVERSATION @handle WITH CLEANUP
END
@jdaigle
jdaigle / gist:2781344
Created May 24, 2012 12:38
SQL Server Service Broker: Short Script to clear DISCONNECTED_INBOUND conversations
DECLARE @handle UNIQUEIDENTIFIER;
WHILE (SELECT COUNT(*) from sys.conversation_endpoints (nolock) where state_desc = 'DISCONNECTED_INBOUND') > 0
BEGIN
SELECT TOP 1 @handle = conversation_handle from sys.conversation_endpoints (nolock) where state_desc = 'DISCONNECTED_INBOUND';
END CONVERSATION @handle WITH CLEANUP
END
<html>
<head><title></title></head>
<body>
<form method="post" action="https://apollo.tfs2.com/Secure/login.aspx">
Username: <input type="text" name="username" /><br />
Password: <input type="password" name="password" /><br />
<input type="submit" />
</form>
</body>
</html>
@jdaigle
jdaigle / gist:2222148
Created March 28, 2012 00:35
Coding Conventions

Stolen from: http://aspnetwebstack.codeplex.com/wikipage?title=CodingConventions

= C# coding conventions =

In general, we have strived to use a style which is compatible with the out-of-the-box defaults for Visual Studio. In particular, this means we use Allman bracing style.

Some other rules we follow:

  • Private fields are prefixed with an underscore and camel-cased.
  • Always include curly braces around blocks, even when they would be optional.