30.06.2013 Views

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SQL Server Team-based Development - Red Gate Software

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 10: Automating CRUD<br />

Automatically Generating Simple INSERT<br />

Statements<br />

The INSERT statement is somewhat of an anticlimax after all this. I won't show it here<br />

but, again, it's available with the code download (Ch10_InsertIntoTemplate.sql). The way<br />

the template is used is identical, so I won't show that either. It produces some nice code,<br />

like that shown in Listing 10-10.<br />

INSERT INTO [Production].[WorkOrder] /*Manufacturing work orders.*/<br />

( ProductID , /*Product identification number. Foreign key to Product.<br />

ProductID.*/<br />

OrderQty , /*Product quantity to build.*/<br />

ScrappedQty , /*Quantity that failed inspection.*/<br />

StartDate , /*Work order start date.*/<br />

EndDate , /*Work order end date.*/<br />

DueDate , /*Work order due date.*/<br />

ScrapReasonID , /*Reason for inspection failure.*/<br />

ModifiedDate /*Date and time the record was last updated.*/<br />

)<br />

VALUES ( 327 , /*Product identification number. Foreign key to Product.<br />

ProductID.*/<br />

3 , /*Product quantity to build.*/<br />

2 , /*Quantity that failed inspection.*/<br />

'1/4/2010' , /*Work order start date.*/<br />

'3/5/2010' , /*Work order end date.*/<br />

'4/5/2010' , /*Work order due date.*/<br />

2 , /*Reason for inspection failure.*/<br />

'11/07/2010' /*Date and time the record was last updated.*/<br />

)<br />

Listing 10-10: An auto-generated INSERT statement.<br />

Apologies if I've caused any chaos in the AdventureWorks business, with my guesses at<br />

legitimate values!<br />

308

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

Saved successfully!

Ooh no, something went wrong!