Wednesday, April 19, 2006
Thursday, April 13, 2006
Internal storage of the DateTime datatype
When you look at the books online this is the explanation:
"Values with the datetime data type are stored internally by the Microsoft
SQL Server 2005 Database Engine as two 4-byte integers. The first 4 bytes store
the number of days before or after the base date: January 1, 1900. The base date
is the system reference date. The other 4 bytes store the time of day
represented as the number of milliseconds after midnight."
It may be hard to believe but this is exactly what SQL Server does. You send him a date and time and he calculates the number of days since 1900-01-01 and the number of ticks since 00:00 for that date. SQL Server does NOT care about timezone and daylight savings time. If you really need to take these into account I suggest you save the offset between the UTC date and the local date and the UTC date. I give preference to take both the times from the client so you don't create problems because of time differences between the server and the client (unless you can guarantee in-sync clients).
Here is a little script that demonstrates the internal storage:
DECLARE @theDate datetime
SET @theDate = '2006-04-14 14:00'
SELECT CAST(SUBSTRING(CAST(@theDate AS varbinary), 1, 4) AS int)
SELECT CAST(SUBSTRING(CAST(@theDate AS varbinary), 5, 4) AS int)
SELECT CONVERT(char(10),DATEADD(d, 38819, '1900-01-01'), 120) AS 'theDate'
SELECT CONVERT(char(10), DATEADD(s, (15120000 / 300), '00:00'), 108) AS 'theTime'
Monday, April 10, 2006
SSIS Performance Whitepaper
This is a must read if you want high performance SSIS Packages.
Friday, April 07, 2006
Best Practices Analyzer for SQL Server 2005
The even better news is that they want to hear from you what you would like to see in this tool. So visit their blog and post your comments!
Thursday, April 06, 2006
SQL Server 2005 Service Pack 1
I'm sure looking forward to it since many people wait for the first service pack before they consider using the product for production purposes.
SQL Server 2005 Upgrade Handbook
Wednesday, April 05, 2006
Blank message box when starting SQL Server Management Studio

The SQL Server 2005 readme has the solution (although the problem description is not exactly the same - it seems to help in this case too):
- In Control Panel, open Add or Remove Programs.
- Click Microsoft .NET Framework 2.0.
- Click Change/Remove.
- Click Repair, and then click Next.
- When the repair is completed, restart the computer if you are prompted to do this
Sunday, April 02, 2006
Random record CTE type thing
Here is the solution I came up with, it's a little fun with CTEs and the RowNumber function.
WITH RepeatCTE (RowNumber, LogID)
AS
( SELECT ROW_NUMBER() OVER(ORDER BY newID()) as RowNumber, newID() LogID UNION ALL
SELECT RowNumber + 1 as RowNumber, newID() LogID FROM RepeatCTE
)
SELECT TOP 400 * FROM RepeatCTE OPTION (MAXRECURSION 0);
Tuesday, March 28, 2006
An unexpected error occurred in Report Processing. (rsUnexpectedError) - Hotfix pending
As soon as I receive information about the hotfix I will let you know.
*EDIT*
I have received the hotfix and will probably be testing it next week. The hotfix only solves the Report Manager side of the problem since the Visual Studio side of it has to be fixed there. There is no hotfix planned for Visual Studio 2005 but "it will be fixed in the future" was the answer to my question.
Tuesday, March 21, 2006
Jolt winner - Database Engines and data tools
Can you guess without clicking? :-D
Monday, March 20, 2006
One big lookup table vs many small lookup tables
While I do agree that one big lookup table complicates things in terms of integrity and data management there are a couple of arguments I disagree with.
Locking and blocking increases
The nature of a lookup table is read-only and given this I would suspect that only shared locks are being taken on the lookup table. So how would you experience locking and blocking in such a scenario?
You create a hotspot on the disk
I don't see why you would have hotspots on a read-only lookup table. Being a hot table means that all the pages of that table would probably be in your data cache - meaning less disk I/O once the pages have been cached. You can even force the table to stay in memory by pinning it, but I don't think many people actually use this technique since SQL Server handles data caching quite well.
I think like any database question the only answer here is: "it all depends". We have many domain specific lookup tables but we also have a big lookup table with over 300 different types. In a database with 400 tables I wouldn't want to create 300 additional tables for simple lookups where most of them would contain 3 to 4 records.
Thursday, March 16, 2006
Wednesday, March 15, 2006
Foreign keys and indexes
Your first task is to detect the foreign keys that have missing indexes. I've created the following query for SQL Server 2005. I have to test it some more to be sure it covers everything but on my little test database it seems to work fine. This is obviously a starting point and you can extend the query quite easily. I'm not checking if the index is too wide to be considered yet, but obviously none of you guys have such wide indexes right?
I'll give it a try on a bigger database tomorrow since it's getting kind of late now ;-)
SELECT fk.Name as 'ForeignKey', OBJECT_NAME(fk.parent_object_id) as 'ChildTable',
OBJECT_NAME(fk.referenced_object_id) as 'ParentTable', c.Name as 'Column', i.Name as 'ValidIndex'
FROM sys.foreign_keys fk
INNER JOIN sys.foreign_key_columns fkc ON fk.object_id = fkc.constraint_object_id
INNER JOIN sys.columns c ON c.object_id = fk.parent_object_id AND c.column_id = fkc.parent_column_id
LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = fk.parent_object_id AND c.column_id = ic.column_id AND ic.index_column_id = 1
LEFT OUTER JOIN sys.indexes i ON i.object_id = ic.object_id AND i.index_id = ic.index_id
ORDER BY ChildTable, ParentTable
Monday, March 13, 2006
DevDays 2006 - Clarification
Maybe this is the real problem in Belgium, Database Developers are kind of an unknown species and we don't see many projects that actually have people that do just that. I hope more and more companies will start to understand the importance of Database Developers so the DevDays can have a separate Database Developers track :-D
Sunday, March 12, 2006
4GB of VAS under WOW, does it really worth it?
Also check out this suggestion coming from Greg Low (MVP). Although it is a feature in Oracle I still think it is a great idea :-) Being able to define your variable type as the column type gets rid of the sometimes painful type mismatches between parameters/variables and column data types. Having the wrong datatype can cause very odd behavior from the Query Optimizer. It also saves you a lot of work when you change the datatype of a specific column. Go VOTE :-D
From the suggestion: DECLARE @TradingName dbo.Customers.TradingName
Wednesday, March 08, 2006
DevDays 2006
To be honest I wasn't too thrilled about the sessions, most of the content was too high level to be interesting. I think the technologies presented are already 'too old' to talk about them in such a way. Most of us freaky developers read too much about it or even worked too much with them already.
I was impressed by the visual effects in Vista though. It looks like something in a science fiction movie and I got the urge to grab the windows in a virtual reality kind of way :-) The upgrade-your-memory-by-using-a-usb-stick was really 'funky' too. Apart from that the deployment options seem quite impressive. Unfortunately I took the SQL track for the rest of the day so I didn't get a chance to see some more new features.
Another interesting thing is the creation of the Belgian SQL Server User Group (http://www.bemssug.org/). Finally some Belgian activity in the SQL Server world; the development side of SQL Server is often forgotten in Belgium so I hope these guys will have some interest in that side of the SQL Server story too.
Wednesday, March 01, 2006
GRANT EXECUTE
SQL Server 2005 has a great solution to this: GRANT EXECUTE
You can now create a database user role that has execute permissions on all the objects in that database.
CREATE ROLE db_ICanExecute
GO
GRANT EXECUTE TO db_ICanExecute
GO
Monday, February 27, 2006
Fun with jobs and the public role and proxies
- When you execute a job and change the data sources the information is NOT stored and the next execution resets the connection information. Using a config file is definitely the way to go :-)
- Proxy accounts with the public role assigned to it have a problem removing this role.
USE [master]
GO
CREATE CREDENTIAL [myCredentials] WITH IDENTITY = N'svcaccount',
SECRET = N'xxxxxxxxx'
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_add_proxy @proxy_name=N'myProxy',
@credential_name=N'myCredentials', @enabled=1
GO
EXEC msdb.dbo.sp_grant_proxy_to_subsystem @proxy_name=N'myProxy',
@subsystem_id=11
GO
EXEC msdb.dbo.sp_grant_login_to_proxy @proxy_name=N'myProxy',
@msdb_role=N'public'
GO
USE [msdb]
GO
EXEC msdb.dbo.sp_revoke_login_from_proxy @proxy_name=N'myProxy',
@name=N'public'
GO
This results in the following error message: "Msg 14523, Level 16,
State 1, Procedure sp_revoke_login_from_proxy, Line 63 "public" has not been granted permission to use proxy "myProxy"."
Also notice the @enabled parameter in the sp_add_proxy call. We can't find this in the interface but when this parameter is set to 0 the proxy is disabled. The problem is that you CAN select
disabled proxies as the account to run the job with but the job fails on execution.
Wednesday, February 22, 2006
Improving Data Security by Using SQL Server 2005
Enjoy!
Tuesday, February 21, 2006
SQL Server 2005 Upgrade Advisor
It is able to check the following:
- SQL Server
- Analysis Services
- Notification Services
- Reporting Services
- Data Transformation Services
Do note that in order to check Reporting Services the Upgrade Advisor needs to be installed on the Report Server, the other services can be checked remotely.
You can choose to check your database(s), a trace file or a SQL batch. When the analysis has been completed a very clear report is created stating the current problems. These are expandable and contain more detailed information. Most of the details contain a link with even more detail on the problem and more important... how to fix it! When applicable the list of objects that are affected by this problem is available too.
This is really a great tool and I would advise you to ALWAYS run it if you are planning to upgrade a database. There are also other tools available when you want to migrate from Oracle. I think other database migration tools will be available too in the future.
