Monday, March 31, 2008

Windows Mobile still a second class citizen in Microsoft's eyes?

I really enjoyed the Heroes Happen Here launch in Birmingham last month. Especially the sessions by Andy Wigley and Daniel Moth.

It's great to see Microsoft including Mobile development along with development for the desktop and the web. (Especially as they are dropping MEDC for the same reasons.) It just seems a bit off that they hold an event to promote it, but then only provide copies of the tools to develop for the desktop and web. (Copies of VS2008 standard were given to attendies, but only VS2008 Professional has the facility to develop for Mobile devices.)

I can see Microsofts argument for not including Mobile support in the standard edition. Not everyone wants it. It's probably not a good idea for any Tom, Dick or Harry to be able to create Mobile apps, as tey probably wouldn't be able to install them. (Most WM devices requiring M2M certificates for installation.) But it feels like Microsoft were saying: You're professionals so you should know about developing for Windows Mobile. But we're not going to give you the tools to do it.

I guess I'm probably just a bit miffed as I was hoping to be able to use VS2008 to develop mobile apps using CF v3.5. Unfortunately I can't afford to buy my own copy of VS2008 Professional 0r an MSDN subscription.

Thursday, March 27, 2008

Trigger without a cursor example

From an example I wrote for someone at work.

ORIGINAL
CREATE TRIGGER S0787_RegionCodes_Insert ON RegionCodes
FOR INSERT
AS
DECLARE @rgnCode varChar(5)
DECLARE InsertedCursor CURSOR FOR
select rgnCode from Inserted
OPEN InsertedCursor
FETCH NEXT FROM InsertedCursor INTO @rgnCode
WHILE @@FETCH_STATUS=0
begin
SET NOCOUNT ON;
Insert InTo S0787_POExportConfig (rgnCode) values (@rgnCode);
Insert InTo S0787_POExportBatchGen (rgnCode) values (@rgnCode);
SET NOCOUNT OFF;
end
FETCH NEXT FROM InsertedCursor INTO @rgnCode
CLOSE InsertedCursor
DEALLOCATE InsertedCursor
GO

This can be rewritten in the following way

NEW
CREATE TRIGGER S0787_RegionCodes_Insert ON RegionCodes
FOR INSERT
AS
SET NOCOUNT ON;
INSERT INTO S0787_POExportConfig (rgnCode)
SELECT rgnCode FROM Inserted
WHERE rgnCode <> ''

INSERT INTO S0787_POExportBatchGen (rgnCode)
SELECT rgnCode FROM Inserted
WHERE rgnCode <> ''
GO

On a single row insertion, the original trigger (according to Profiler) made 285 reads and had a duration of 156. The new trigger made 10 reads and had a duration of 16.

This is orders of magnitude faster.

Don't use cursors, when you don't have to!