SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Evaluation time for functions SQL2005 / SQL2000


Evaluation time for functions SQL2005 / SQL2000

Author
Message
Eric Weir
Eric Weir
Forum Newbie
Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)Forum Newbie (6 reputation)

Group: General Forum Members
Points: 6 Visits: 95
I have a database that has recently migrated from SQL 2000 to SQL2005. I have a problem with the evaluation of a function which did not cause problems in SQL 2000 but does in 2005.

The function ( getNextID() ) generates a new ID value for a table. There is no Identity column defined on that table, its just an int column and this function is used to generate the next sequential value (... I inherited this database, I don't know why they didn't just define an Identity column).

The problem arises when inserting more than one new row with code like this:
INSERT INTO Project (ProjectID, [Description], [Manager])
SELECT dbo.GetNextID(), [ProjectDescription], [ProjectManager]
FROM tmpImportTable_Project

In SQL 2000 this works correctly when you are inserting > 1 new row. That is, the insert statement correctly generates a sequential value for each new row.
In SQl 2005 however, the function seems to be evaluated for all new rows prior to any rows being inserted, and not evaluated after each and every new row is inserted. So it doesn't generate a sequential value for each new row, it generates the same value for each and every row. Any inserts then fail on the second row because of a PK violation.

I can write a bit of script to generate the required sequential IDs; thats not a problem. But I wondered if anyone had met this problem before and if they had a resolution for it?
Is there perhaps a global setting in 2005 that would affect the evaluation-time of functions?


Kind regards,
Eric.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search