13
Tweet Tweet – What Developers Need to Know About SQL Server Brent Ozar SQL Server DBA, Microsoft MVP Microsoft Certified Master of SQL Server

Tweet Tweet – What Developers Need to Know about SQL Server

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Tweet Tweet – What Developers Need to Know about SQL Server

Tweet Tweet – What Developers Need to Know About SQL Server

Brent OzarSQL Server DBA, Microsoft MVPMicrosoft Certified Master of SQL Server

Page 2: Tweet Tweet – What Developers Need to Know about SQL Server

2 Room for text Global Marketing

Intro

I recently hosted a Twitter Chat on everything developers would need to know about designing databases. I was joined by Richard Douglas, a SQL server for Dell Software and also the Editor in Chief of SQLServerpedia.com.

We asked our followers and participants to share their tips and best practices using the hashtag: #dellsql. The following slideshow content is what we deemed as most useful to our audience. Enjoy!

Page 3: Tweet Tweet – What Developers Need to Know about SQL Server

3 Room for text Global Marketing

@SQLintheWild says “Get it Right the First Time”

• Understand the changing database design from the beginning

Remember

• As your app grows and more stuff interfaces with it, simply refactoring the database is no longer an option

Page 4: Tweet Tweet – What Developers Need to Know about SQL Server

4 Room for text Global Marketing

@alzdba says “Use the Right Data Types”

• Tell the database when a field is unique and relates to a field in another table

• Set up constraints or foreign key relationships

Remember

• This can actually make your queries faster because SQL Server uses this knowledge to build better execution plans

Page 5: Tweet Tweet – What Developers Need to Know about SQL Server

5 Room for text Global Marketing

@MarkStacey says “Use DATE if You Don’t Need Time”• DATE is a narrower field

than DATETIME, requiring less storage.

Remember

• You can pack more rows per page on your date indexes

Page 6: Tweet Tweet – What Developers Need to Know about SQL Server

6 Room for text Global Marketing

@RealSQLGuy says “NVACHAR is Not an All-Purpose Datatype”• Use the bare minimum and size

data needs

Remember

• NVARCHAR is Unicode, which uses 2x the storage space for as compared to just plain VARCHAR.

• This means you can cache half as many rows in memory, plus your storage IO takes twice as long

Page 7: Tweet Tweet – What Developers Need to Know about SQL Server

7 Room for text Global Marketing

@SirSQL says “Blobs Rarely Belong in the Database”

• Varbinary (max) should be an anomaly

Remember

• Licensing databases is way more expensive than licensing a file server

Page 8: Tweet Tweet – What Developers Need to Know about SQL Server

8 Room for text Global Marketing

@Ruirrib says “Not all Types are Good for Primary Keys”• Primary keys & clustering

keys should be:– Narrow– Static– Ever-increasing

Remember • Don’t go redesigning an

existing database to change this, because it’s probably not your biggest bottleneck

Page 9: Tweet Tweet – What Developers Need to Know about SQL Server

9 Room for text Global Marketing

@dpenton says “If Your First Inclination is to use a Trigger, Stop”• Believe it or not, you could be

viewing the problem wrong

• Consider moving to an asynchronous solution

Page 10: Tweet Tweet – What Developers Need to Know about SQL Server

10 Room for text Global Marketing

@RealSQLGuy says “There’s No Need for an Index on Every Column in the Table” • Narrow, one-field indexes are

usually less useful

Remember

• If you insert a record into a table with 10 non-clustered indexes, you’ll be doing 11 (or more) writes to disk each time. Why bother if you could save time with one-field indexes?

Page 11: Tweet Tweet – What Developers Need to Know about SQL Server

11 Room for text Global Marketing

@Nick Craver says “Don’t Run SSMS Index Suggestions Blindly”• SQL SMS’s index suggestions

have no concerns about adding overhead to inserts/updates/deletes

Remember

• More often than not, they’re supersets or subsets of existing indexes

Page 12: Tweet Tweet – What Developers Need to Know about SQL Server

12 Room for text Global Marketing

@SQLintheWild says “Know the Common Queries that Run Against Indexes for Table Structures” • Word to the wise: don’t go crazy

adding indexes with guesses when you first get started with a new database

Remember

• Indexes are easy to add later – wait to see how the queries actually shape up

Page 13: Tweet Tweet – What Developers Need to Know about SQL Server

13 Room for text Global Marketing

For More Information

• To view the twitter chat, go to: http://bit.ly/HVh4m3

• To learn more about Solutions for SQL Server: http://dell.to/1cxeM7Q