T-SQL Tuesday #002: A Puzzling Situation – Updating Statistics

This post is in response to Adam Machanic’s “T-SQL Tuesday #002:  A Puzzling Situation”.  One of the databases I manage has multiple very large tables.  The biggest contains about 4.8 billion rows.  We had to move this database to another server and while we did, we decided we needed to update the statistics.  Note it [...]

Script for Generating Random Data

I often need to fill up tables with random data to test data conversion scripts, foreign keys, indexes, etc. Here’s my “Go To” script for coming up with random data. I usually base it off this and change the name of the table to insert data into, but this has the things I [...]

SQL and Twitter

One of my goals for 2010 is to get more involved in the SQL server community.  A great way to do this is to use twitter.  I’ve been using twitter since January of 2009 – you can follow me here.  I’ve had my high usage times (where I check it and post to it all [...]

Get Fairly Accurate Table Counts

Here’s a simple script that I use often – a quick hitter to find table row counts, that doesn’t use the Select Count(*). It uses the sysindexes table thus the reason it’s called “fairly accurate”.

SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER [...]

Script for Running Events

Here’s a script I created to determine when I was going to be at specific miles for a marathon. It’ll give you your miles per hour and your minutes per mile. Then it’ll calculate at what time you will be at different mile marks.

Set nocount on
Declare @FTime datetime,
@Dist float,
@RStartTime datetime,
@BDown float

———————————–
—-Change these for [...]

Script to Create a Script Header….

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
– Creates a header for scripts –
– Pastes [...]