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

Create successful ePaper yourself

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

Chapter 6: Reusing T-<strong>SQL</strong> Code<br />

Unfortunately, performance considerations may prevent us from reusing our code to<br />

the fullest. Yet, with careful benchmarking, we can usually find a nice compromise and<br />

develop code that is easy to maintain but still performs well enough.<br />

Specifically, I hope the chapter has taught you the following lessons in code reuse:<br />

• views are useful for simple reuse of non-parameterized queries<br />

• for reuse of parameterized queries, inline UDFs are often preferable to<br />

stored procedures<br />

• be wary of performance issues with scalar and multi-statement table-valued UDFs<br />

• if possible, enforce reusable business logic in a simple constraint, or possibly a filtered<br />

index in <strong>SQL</strong> 2008 and upwards<br />

• for more complex logic, triggers often offer the most convenient means of promoting<br />

reuse, but they require extensive testing.<br />

198

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

Saved successfully!

Ooh no, something went wrong!