Wednesday, May 30, 2007

SELECT "YYYYDD" datetime

Can you explain about this ?

1st sql script :

SELECT CONVERT(VARCHAR(6),GETDATE(), 112)

------
200705

(1 row(s) affected)


2nd sql script :

SELECT CONVERT(VARCHAR(4),YEAR(GETDATE()), 112) + CONVERT(VARCHAR(2),MONTH(GETDATE()), 112)

------
20075

(1 row(s) affected)


Why 2nd sql script doesn't show the same result with the 1st sql script ?

UNION and GROUPING

Still about using UNION, how sql server grouping this result?

SELECT '200701'
UNION
SELECT '200701'
UNION
SELECT '200701'
UNION
SELECT '200701'
UNION
SELECT '198001'

output
------
198001
200701

(2 row(s) affected)

How can SQL Server order this result

How can SQL Server order this result?

SELECT '200702'
UNION
SELECT '200701'
UNION
SELECT '200703'
UNION
SELECT '200705'
UNION
SELECT '198001'

output
------
198001
200701
200702
200703
200705

(5 row(s) affected)

Thursday, May 24, 2007

Transaction Log Optimization

* Pre-allocate the log to appropriate size

* Minimize auto growths

* Log might NOT show 0 Percent Log Used after backup for example - the % Log Used will be ~6%

* Disk Bound Systems might experience some performance degradation at log backup

* Consider RAID 1+0 instead of RAID 1, RAID 5 generally is not recommended

* Optimize existing file – minimize VLFs

- - -

source : SQL Server Community In touch

How to Creating Databases

* Inherit initial properties from model database

* Change to model will affect ALL databases created AFTER the change made.
Note : TempDb is re-Created on each system restart. Might be a good idea for data types that are needed for temp table/objects

* Define logical file names

* Define physical location

* Define auto growth setting

* Create DataBase [junkDb] on Primary
(Name = N'JunkDbData', FileName = N'Physical FileName',
Size = 10, --kb, mb, gb, tb
FileGrowth = 10%, --kb, mb, gb, tb
MaxSize = 15) --kb, mb, gb, tb

Log on
(Name=N'JunkDbLog',
FileName = N'Physical FileName',
Size = 10, --kb, mb, gb, tb
FileGrowth = 10%, --kb, mb, gb, tb
MaxSize = unlimited)

* Default for filegrowth is 10%

* Default for MAXSIZE is Unlimited