Database Heaps

A heap is a table without a clustered index. One or more nonclustered indexes can be created on tables stored as a heap. Data is stored in the heap without specifying an order. Usually data is initially stored in the order in which is the rows are inserted into the table, but the Database Engine... » read more

Temp Tables vs Table Variables

There are two types of temporary tables that you’ll use: local and global, and these have a specific designation. Local tables are designated with one pound sign and global temporary tables are designated with two pound signs. If you create a table that doesn’t have a pound sign, or two pound signs, in front of... » read more

SQL Server Pages

SQL Server stores data in 8K pages. The narrower your rows are, so, for example, if you had a table that was just simply an integer in a varchar, the more rows will fit on a single page. SQL Server reads those pages off of disk and into memory in order to service your queries... » read more

GUID

GUIDs or unique identifiers have the benefit of being globally unique across machines and databases. This gives us a tremendous benefit in that we know that we’re always going to have a unique value.  It’s composed partially of a seed that starts with the MAC address of the computer it’s on, and then the time... » read more

Things to Avoid with SQL Server Database

Avoid storing files in the database Makes database size very hard to manage. Backups and restore. Instead store files else where and store pointers to files in the database. Avoid storing business logic in the database Hard to maintain. Example: don’t use database to send emails or move files. Move business logic to application layer.... » read more

Statistics IO and Time

SET STATISTICS IO, TIME ON Statistics IO is going to give us the number of IO operations that SQL Server’s going to do to service our queries, and it’s going to break that down by logical reads from memory and physical reads from disk.  The time statistic is just going to give us the actual... » read more

Reading Execution Plans

Estimate Plan vs Actual Plan Depends on the statistics your database has about your data. If you see a large differential between the estimated number of rows and the actual number of rows, it can be an indication that SQL Server does not have the proper statistics on the underlying tables and indexes that are... » read more

Query Execution Plan

What happens when you issue a query to SQL Server. #1 SQL Server is going to parse the syntax of your query.  SQL Server is going to check to see if your T-SQL that you’re submitting is valid and that all of the objects exist. This is a basic check just to make sure all... » read more

SQL Server TempDB

TempDB is used for many operations, such as user-created temporary objects, internal temporary objects and version stores and certain features like online re-indexing, multiple active record sets (MARS) and others. Because of all these uses, TempDB should be installed on a fast drive (like SSD) and even set to multiple disk drives. You should also... » read more

Fine Tuning SQL Server Databases

Removing Unnecessary Indexes Index maintenance requires lots of CPU and I/O. Every time we insert data into a database, SQL Server also needs to update the indexes, so it is better to remove them if they are not used. SQL Server Installation And Database Setup When setting up a database, we need to keep data... » read more