473,511 Members | 15,384 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IDENT_CURRENT and empty table

Hi,

can somebody explain me, why the IDENT_CURRENT from an empty table is 1?
After insert of the first record it is still 1 (assuming that start value
is 1) which is okay. But if i check the IDENT_CURRENT from a newly created
table the result should be NULL, or not?

bye,
Helmut
Sep 18 '05 #1
10 5658
>> But if i check the IDENT_CURRENT from a newly created table the result should be NULL, or not? <<

What would a NULL value mean? Why not zero? Remember IDENTITY is
proprietary and non-relational, so it can do anything it wants.

Think about how it would work if you had a 1950's sequential tape file
system. The counter starts at one and is incremented after the
insertion instead of before. It is the position of the read/write head
of the maganeitc tape drive.

Sep 18 '05 #2
Am 18 Sep 2005 07:57:39 -0700 schrieb --CELKO--:
But if i check the IDENT_CURRENT from a newly created table the result should be NULL, or not? <<


What would a NULL value mean? Why not zero? Remember IDENTITY is
proprietary and non-relational, so it can do anything it wants.

Think about how it would work if you had a 1950's sequential tape file
system. The counter starts at one and is incremented after the
insertion instead of before. It is the position of the read/write head
of the maganeitc tape drive.


We have NULL to mark something as unknown. Why not using it?
In the manual IDENT_CURRENT is described as "gives back the last generated
ident value". So from my logical point of view it cannot give back a value
if it has not generated a value before. And because zero can be a valid
starting value it can't give back zero.
Maybe it would be better we have a IDENT_NEXT which shows the next value
which will be used, instead of IDENT_CURRENT. This could avoid such
misconception.

bye,
Helmut

Sep 18 '05 #3
http://support.microsoft.com/default...b;en-us;835188

--
Hope this helps.

Dan Guzman
SQL Server MVP

"helmut woess" <hw@iis.at> wrote in message
news:1q*****************************@40tude.net...
Hi,

can somebody explain me, why the IDENT_CURRENT from an empty table is 1?
After insert of the first record it is still 1 (assuming that start value
is 1) which is okay. But if i check the IDENT_CURRENT from a newly created
table the result should be NULL, or not?

bye,
Helmut

Sep 18 '05 #4
Am Sun, 18 Sep 2005 17:58:46 GMT schrieb Dan Guzman:
http://support.microsoft.com/default...b;en-us;835188


Hmmm, i am not sure what to do with this information. If it is a bug why
was it not fixed in one of the next service packs?
And there is no definition what the result will be after fixing the bug.
And i did not find any information if this bug is fixed in SQL2005.

In the meantime i wrote an UDF to check if the table is empty and then give
me the right result. So it doesn't matter if Microsoft fixes the bug or
not.

but thanks for your information,
Helmut
Sep 19 '05 #5
helmut woess (hw@iis.at) writes:
Am Sun, 18 Sep 2005 17:58:46 GMT schrieb Dan Guzman:
http://support.microsoft.com/default...b;en-us;835188


Hmmm, i am not sure what to do with this information. If it is a bug why
was it not fixed in one of the next service packs?
And there is no definition what the result will be after fixing the bug.
And i did not find any information if this bug is fixed in SQL2005.


The behaviour is the same in SQL 2005.

But the funny thing is that Books Online for SQL 2005 explicitly says that
you should get NULL back in this case...
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Sep 19 '05 #6
As Erland mentioned, the bug hasn't yet been addressed. Your UDF
work-around is probably the best apporach.

May I ask why you need to use IDENT_CURRENT? The function has a global
scope so it needs to be used with caution in a multi-user environment.

--
Hope this helps.

Dan Guzman
SQL Server MVP

"helmut woess" <hw@iis.at> wrote in message
news:1v*****************************@40tude.net...
Am Sun, 18 Sep 2005 17:58:46 GMT schrieb Dan Guzman:
http://support.microsoft.com/default...b;en-us;835188


Hmmm, i am not sure what to do with this information. If it is a bug why
was it not fixed in one of the next service packs?
And there is no definition what the result will be after fixing the bug.
And i did not find any information if this bug is fixed in SQL2005.

In the meantime i wrote an UDF to check if the table is empty and then
give
me the right result. So it doesn't matter if Microsoft fixes the bug or
not.

but thanks for your information,
Helmut

Sep 20 '05 #7
Erland Sommarskog (es****@sommarskog.se) writes:
helmut woess (hw@iis.at) writes:
Am Sun, 18 Sep 2005 17:58:46 GMT schrieb Dan Guzman:
http://support.microsoft.com/default...b;en-us;835188


Hmmm, i am not sure what to do with this information. If it is a bug why
was it not fixed in one of the next service packs?
And there is no definition what the result will be after fixing the bug.
And i did not find any information if this bug is fixed in SQL2005.


The behaviour is the same in SQL 2005.

But the funny thing is that Books Online for SQL 2005 explicitly says that
you should get NULL back in this case...


Got an update: Books Online for 2005 is wrong and will be updated.
The current behaviour will not change, because it could cause compatibility
issues.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Sep 20 '05 #8
Am Tue, 20 Sep 2005 12:39:32 GMT schrieb Dan Guzman:
As Erland mentioned, the bug hasn't yet been addressed. Your UDF
work-around is probably the best apporach.

May I ask why you need to use IDENT_CURRENT? The function has a global
scope so it needs to be used with caution in a multi-user environment.


Hello,

sorry for delay, but i was tied up with vacation :-))
The reason why i read this value in my application is as following:
All records own an identity field (which is always the primary key), which
is used to log all data activities in a log table which has an identity
field too. When i add a new record, then this record gets its identity
value and the trigger afterwards logs this insert into the log table which
creates a new record in the log table. But this insert in the log table
changes @@IDENTITY, and the ado component in my application gets this value
as new identity value, not the value from the original insert - i needed
some days to find out this behaviour. And my grid for displaying the data
jumps to the wrong record ...
So i read this value before i do the post and after posting the data i do a
refresh of the data and a repositioning in the grid to the identity value i
got with reading ident_current before.
So if something goes wrong the worst case could be that the grid shows a
wrong record. But because in my application every record has a lot of data
to set and everything has to be done by hand and there are max. 3 users at
the same time adding records into the same table i can live with this risk.

bye,
Helmut

Sep 27 '05 #9
Assuming you are using SQL Server 2000 then use SCOPE_IDENTITY() rather
than @@IDENTITY. SCOPE_IDENTITY won't be affected by an insert in the
trigger.

--
David Portas
SQL Server MVP
--

Sep 27 '05 #10
Am 27 Sep 2005 02:04:29 -0700 schrieb David Portas:
Assuming you are using SQL Server 2000 then use SCOPE_IDENTITY() rather
than @@IDENTITY. SCOPE_IDENTITY won't be affected by an insert in the
trigger.


I think there was a litte misunderstanding, i don't use @@identity, i use
ident_current(). The problem is not in the trigger, it is in the ADO
component from Delphi. It looks like the component is reading @@identity
instead of scope_identity(), so it gets the wrong value.

bye,
Helmut
Sep 27 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
3259
by: Agent Mulder | last post by:
Hi group, Almost 3 weeks ago I posted a short question here and in comp.std.c++ and I got exactly 1 respons, from Kevin Goodsell. He said he didn't want it. I post it here again, this time in a...
12
17078
by: Stefan Weiss | last post by:
Hi. (this is somewhat similar to yesterday's thread about empty links) I noticed that Tidy issues warnings whenever it encounters empty tags, and strips those tags if cleanup was requested....
0
1827
by: trint | last post by:
I need to immediately get the last IDENTITY from an insert with IDENT_CURRENT in my c# code...I can use this and get it in the query analyzer, but I don't know how to get it in my code to a string....
22
4203
by: EMW | last post by:
Hi, I managed to create a SQL server database and a table in it. The table is empty and that brings me to my next chalenge: How can I get the info in the table in the dataset to go in an empty...
6
7830
by: john | last post by:
Hi there I have small problem with IDENT_CURRENT... We have a table where PK is generated automatically. What I want is to get that value and insert it to another, corresponding table. So here...
2
14148
by: Jay | last post by:
I have a SQL Server table with nvarchar type column which has not null constraint. I am inserting empty string ("") from Java to the table column. When I export this table into .csv file using bcp...
1
1813
by: Iceman | last post by:
I am using IDENT_CURRENT to get the id of a record from a table and using it somewhere else (for data insertion, updating). I understand that this not correct from a multi-user perspective since...
5
4902
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
8
3878
by: thatcollegeguy | last post by:
http://smarterfootball.com/exits/theHTML.html I am not sure what is wrong w/ this code. The main issue is that the table that is in the initial html will empty its td but the table that I load...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7508
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5662
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3212
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.