Greg Larsen's Blog

March 2008 - Posts

  • Save Disk Space with SQL Server 2008 DATETIME2 Data Type

    I was spending some time over the last few weeks researching new features in SQL Server 2008 for a presentation I gave today at the Olympia Area SQL Server User Group in Tumwater, Washington, USA.  So of course I had to take a closer look at the new date/time data types as part of this review.  

    Most everyone knows that there are a number of different date/time related data types coming out with SQL Server 2008.  But for this BLOG post I want to focus in on just one new data type, DATETIME2.  The new DATETIME2 data type is much like the existing DATETIME data type, except that it allows more percision for the time portion of the date/time.  This new data type can now support time values that are accurate to 100 nanoseconds. 

    This new DATETIME2 data type allows you to specify how much percision you want to store in the time portion.  The more percision you want the more disk space it take.  A DATETIME2 data type takes from 6 to 8 bytes depending on the percision.

    While I was building my examples for my user group presentation I built some queries that showed how much storage was taken for each of the different percisions.  While building my DATALENGTH function calls for different DATETIME2 percisions I found out something amazing about the DATETIME2(3) format.  If you use a DATETIME2(3) format for a date/time column instead of a DATETIME data type it stores the same data value but using one less byte.  Thats right 7 bytes instead of 8. 

    Now I know saving 1 byte doesn't seem like a lot.  But now multiple that by the number of different dates you might have in your 10 million record table.  That savings of 1 byte could account for a substainal savings of disk space.  I know disk space is cheap these days. But if you use less disk space to store your records then that equates to more records read per I/O, and faster query performance.  So if you like the exiting percision of DATETIME, then remember to use DATETIME2(3) data type when you start building SQL Server 2008 applications.

    Happy database designing,

    Greg Larsen, MCITP

  • Think Green

    As Saint Patrick’s Day approaches I’m sure a number of you will be thinking about lifting a few green beers at your local watering hole.  Why you are thinking about all the green items that come along with Saint Patty’s day, how about thinking green for your SQL Server environment. 

    So about now you are probably wondering what the heck I am talking about.  Well I’m talking about how you might reduce that carbon foot print for your SQL Server installations.  How are you planning on reducing your consumption of rack/floor space, power, and cooling expenses?

    My green effort is to consider consolidation as our organization starts contemplating moving toward SQL Server 2008. 
    I am researching how I can leverage virtualization along with consolidation to reduce the total cost of ownership for SQL Server 2008. I’m researching Microsoft Virtual Server (http://www.microsoft.com/windowsserversystem/virtualserver/), Microsoft Hyper-V (http://www.microsoft.com/windowsserver2008/en/us/virtualization-consolidation.aspx) and VMWare ESX Server (http://www.vmware.com/products/vi/esx/) as potential vessels to launch me into the virtual world.

    I’d be interested to hear your thoughts on thinking green for your SQL Server environment.  What virtualization strategies are working for you?  Are you doing virtualization only in a development environment, or has the virtualization seed also sprouted in your production environment?  What software/hardware do you find works best for a virtualized SQL Server environment? Please provide your comments and green thumb experiences, so others can cultivate their own virtualization efforts.

    Happy Gardening,
    Gregory A. Larsen, MCITP
  • Sample Databases for SQL Server 2008

    I suppose by now all of you know about the lastest SQL Server 2005  beta (CTP6), which was released in February.  If you have downloaded and installed this beta or any one of the prior CTP’s you will noticed there are no sample databases installed, which of course is normal. 

    If you are going to play with SQL Server 2008 you can create your own database. Then use those databases to experiment and play around with the new features of SQL Server 2008. But I personally like to use the sample databases provided from Microsoft.   

    The advantages of using sample databases is they are already populated and normally have lots of objects and code that take use the new features of SQL Server.  Using these sample DBs allow you to explore the new features of SQL Server without building your own DB.  Also when you are building examples to share like I do on my site (http://sqlserverexamples.com) it allows you to write T-SQL code that can easily be run by anyone that has installed the appropriate Microsoft sample database.  This way you don’t need to spend a great deal of time creating sample data just to share a script to perform a specific task.

    In prior versions of SQL Server we have had sample databases named, “Northwind”, “Pubs”, “AdventureWorks”, “AdventureWorksDW”, and so on .  Well now with SQL Server 2008, Microsoft has provided some new sample databases.  These sample databases are available at CODEPLEX at this location: http://www.codeplex.com/MSFTDBProdSamples/Release/ProjectReleases.aspx?ReleaseId=10901

    I personally have only loaded the AdventureWorks2008 sample DB.  Since this sample database contains a FILESTREAM object I had to enable the file stream feature just to be able to use this sample DB.  You can find out more about installing this sample database here:  http://www.codeplex.com/MSFTDBProdSamples/Wiki/View.aspx?title=AW2008Details

    So if you are looking to jump start you SQL Server 2008 experience consider downloading one of the sample databases provided by Microsoft.  I’ll be writing most of my SQL Server 2008 articles and examples against the AdventureWorks2008 databases.  So if you haven’t already downloaded and installed the AdventureWorks2008 sample DB you might just give it test drive.  In doing this you will learn how to enable the file stream feature. 

    Happy Testing,

    Greg

     



© 2000 - 2007 vDerivatives Limited All Rights Reserved.