Sunday 24 June 2007

More SQL

OPTION (Fast X) hint optimises for returning the first X number of rows first before executing the rest of the query. This can have an effect on overall performance however the tradeoff is that the user can see some results while the rest of the query is executing.

Create Calendar Table
In Visual Studio -> New Project -> Analysis Services Project -> New Data Source
then New Dimension -> Date Template and go from there

Always name table outputs with AS so that the developer is abstracted from the actual table and column names

SQLStressTest - good for testing performance and even debugging.
http://www.apress.com/book/supplementDownload.html?bID=10220&sID=4251

Date Time:
ISO Format is:
yyyy-MM-ddThh:mm:ss.mmm
SQL Server also accepts:
yyyyMMdd hh:mm:ss


Hashing:
SELECT HashBytes('MD2MD4MD5SHASHA1', 'Text')

Dynamic SQL:
sp_executesql - can make use of parameters and hence a) reuse quer planss b) most importantly prevent sql injection.
Useage:
EXEC sp_executesql @sqlStatement, N' @String VARCHAR(255), @Int INT', @SomeString, @SomeNumber

Concurrency Control:
Read Blocking: READ COMMITTED, REPEATABLE READ, SERIALIZABLE
Non Blocking: READ UNCOMMITTED, SNAPSHOT
Usage: SET TRANSACTION ISOLATION LEVEL REPEATABLE READ


No comments: