30.06.2013 Views

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SQL Server Execution Plans - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

INSERT statements<br />

Chapter 2: Graphical <strong>Execution</strong> <strong>Plans</strong> for Basic Queries<br />

INSERT statements are always against a single table. This would lead you to believe<br />

that execution plans will be equally simplistic. However, in order to take into account<br />

rollbacks and data integrity checks, execution plans for insert queries can be quite<br />

complicated.<br />

Listing 2.15 contains a very simple INSERT statement.<br />

INSERT INTO Person.Address<br />

(AddressLine1,<br />

AddressLine2,<br />

City,<br />

StateProvinceID,<br />

PostalCode,<br />

rowguid,<br />

ModifiedDate<br />

)<br />

VALUES (N'1313 Mockingbird Lane', -- AddressLine1 - nvarchar(60)<br />

N'Basement', -- AddressLine2 - nvarchar(60)<br />

N'Springfield', -- City - nvarchar(30)<br />

79, -- StateProvinceID - int<br />

N'02134', -- PostalCode - nvarchar(15)<br />

NEWID(), -- rowguid - uniqueidentifier<br />

GETDATE() -- ModifiedDate - datetime<br />

)<br />

Listing 2.15<br />

There are two ways I could run the query above to generate the execution plan. I could<br />

retrieve an estimated plan, which is what I did. An estimated plan is a plan that is<br />

compiled, but not run. The other method for getting an execution plan would be to wrap<br />

the query in a transaction and roll back that transaction after capturing the execution<br />

plan. I chose to use the estimated plan because it was easier and still suited our needs.<br />

109

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!