Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 19th, 2003, 08:57 AM
Registered User
 
Join Date: Nov 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default MSSQL 2k trigger freak behavior -columns_updated()

Good life,

I have a trouble - when i create table with more than 24 columns (may be it depends) the columns_updated() function returns zero - 0.

May be it is an error of MSSQL engine, may be I'm stupid.

It seems, that only 3B can be addressed :))

I need to use it and don't know about any alternative except of brutal programming :)

Thank you for your interest.

I've made an test example:
Code:
-----------------------------------
/*
if number of columns is higher than 24 (may be it depends)
trigger prints, that no columns were changed
test it with adding or remowing columns
*/


begin tran

CREATE TABLE [dbo].[TestCU] (
 [ID] [int] NOT NULL Identity (1,1) PRIMARY KEY,
 [C01] [int] NULL ,
 [C02] [int] NULL ,
 [C03] [int] NULL ,
 [C04] [int] NULL ,
 [C05] [int] NULL ,
 [C06] [int] NULL ,
 [C07] [int] NULL ,
 [C08] [int] NULL ,
 [C09] [int] NULL ,
 [C10] [int] NULL ,
 [C11] [int] NULL ,
 [C12] [int] NULL ,
 [C13] [int] NULL ,
 [C14] [int] NULL ,
 [C15] [int] NULL ,
 [C16] [int] NULL ,
 [C17] [int] NULL ,
 [C18] [int] NULL ,
 [C19] [int] NULL ,
 [C20] [int] NULL ,
 [C21] [int] NULL ,
 [C22] [int] NULL ,
 [C23] [int] NULL ,
 [C24] [int] NULL ,
/*
 [C25] [int] NULL ,
 [C26] [int] NULL ,
 [C27] [int] NULL ,
 [C28] [int] NULL ,
 [C29] [int] NULL ,
*/

 [CLast] [int] NULL

)

GO
CREATE TRIGGER [trTestCU] ON dbo.TestCU
FOR INSERT, UPDATE, DELETE
AS if columns_updated()>0 print 'YES!, columns were changed'
   else print 'NO!, columns were NOT changed !!! ???'
GO


insert into TestCU (C01,C02,C03,C04,C05,C06) values
(100,65840,15,2003,11,55)

rollback tran

-- [email protected]
 
Old November 19th, 2003, 07:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Um, you are aware that the columns_updated() function returns a bit mask, aren't you?

Each bit in the result is set if the corresponding column has been updated. The first column in the table is the leftmost bit, the second is the next, and so on, with the least significant bit of the result corresponding to the last column of the table.

When you do an INSERT, all columns are considered updated. Thus, the first column is updated, and this will be the most significant bit of the result. When this result is interpreted as an integer (when you compare it to zero) since the high order bit is set, the value is considered negative, which, of course, isn't greater than zero, which is why your trigger is misleading you.

Compare to exactly zero, and I think you'll be OK...

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting to MSSQL-- All about it Chrisman ASP.NET 3.5 Basics 3 May 17th, 2008 03:23 AM
do we have to install MSSQL? angelboy C# 2005 4 January 19th, 2008 05:26 AM
MSSQL 2005 and MSSQL 2000 tiredcat Visual Basic 2005 Basics 0 April 9th, 2007 12:56 AM
Runtime Access 2K and Sql 2K laure Access 0 April 3rd, 2006 08:32 AM
Columns_Updated dlinsko SQL Server 2000 8 July 22nd, 2003 10:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.