T-SQL and Database Development

Writing, reviewing, debugging, and maintaining T-SQL and database code.

478 associated posts232 primary posts

T-SQL & Development

My 3 Favorite Connection String Tips

Connection strings - boring topic, right?  Well, it turns out there's a few things that can save your behind.
Tip 1: Build your application with 3 connection strings.
If you want to scale, write your application from the start with 3 different connection strings:

Writes and real-time reads
Reads that can tolerate data older than 15 seconds (no writes allowed with this connection string)
Reads that can tolerate data several hours old (like reports, and no writes allowed with this string)

Read more about My 3 Favorite Connection String Tips 27 comments — Join the discussion

How Do You Mask Data for Secure Testing?

Data masking, data scrambling, and just plain old obfuscation: these are ways to get developers access to production-quality data for testing purposes without actually giving them real production data.  It's much harder than it looks, though. The Easy Part: Obfuscating Data Developers love working with production data.  Today's privacy-concerned companies aren't quite so keen on…

Read more about How Do You Mask Data for Secure Testing? 23 comments — Join the discussion
T-SQL & Development

Windowing Function Examples for SQL Server

Aggregations and grouping can be a pain in the rear for the novice SQL developer. Way back in 2003, the ANSI/ISO standards people figured this out and added windows and ranking functions to the standard. In 2005, Microsoft added a few of these functions (ROW_NUMBER(), RANK(), DENSE_RANK(), and NTILE()) as well as the OVER() clause…

Read more about Windowing Function Examples for SQL Server 13 comments — Join the discussion
T-SQL & Development

Why Use Schemas?

The ever-insightful Buck Woody (Blog - @BuckWoody) wrote a post telling you to use database schemas.  He writes: "But I still see a lot of applications, developed by shops I know as well as vendors, that don’t make use of a Schema. Everything is piled under dbo.... But if you’ll use them properly you can…

Read more about Why Use Schemas? 100 comments — Join the discussion

How to Import the StackOverflow XML into SQL Server

UPDATE 2013: This code is no longer available. The size of the StackOverflow export has grown beyond what you can import with this method.

Want to play around with the StackOverflow database export?  Here's how to import the XML files into SQL Server, and some notes about the tables and data schema.
Script to Import StackOverflow XML to SQL Server
This T-SQL script will create six stored procedures:

Read more about How to Import the StackOverflow XML into SQL Server 16 comments — Join the discussion
Performance Tuning

SQL Server training for developers: primary keys & indexes

I had to do some developer training last week and I wrote up a paper on the basics of primary keys and indexes. Sure, there's tons of similar stuff around the net, but this is MINE, baby.
Our Table: Phone Numbers
For our evil training purposes, let's say we work for the phone company, and we need a database table with phone numbers. We need to track:

Read more about SQL Server training for developers: primary keys & indexes 8 comments — Join the discussion