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 10 5682
>> 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.
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 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.n et... 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
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
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****@sommarsk og.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
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.n et... 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
Erland Sommarskog (es****@sommars kog.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****@sommarsk og.se
Books Online for SQL Server SP3 at http://www.microsoft.com/sql/techinf...2000/books.asp
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
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
-- This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 thread named 'Empty arguments', because
that is what I got from you. Can you spare a minute and try to see my point?
struct Room
{
Room(bool a=true,bool b=true,bool c=true):Chair(a),Table(b),Bed(c){}
bool Chair,Table,Bed;
|
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. This is okay in
some cases (such as <tbody>), but problematic for other tags (such as
<option>). Some tags (td, th, ...) do not produce warnings when they are
empty.
|
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.
Any help is appreciated.
Thanks,
Trint
|
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 SQL
table?
Is there a short way like the FILL method to get data into the dataset or do
I have to read each datarow in the table and write it one at the time to the
|
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 is what I am doing...
BEGIN TRAN
Insert Into table() --> PK is created.
SELECT IDENT_CURRENT('Table_Name') AS lastValue
COMMIT TRan
| |
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 tool, empty
string gets written as NUL character. Is there any way I can bcp out
empty string as empty string itself instead of NUL to the file?
The bcp command I used to export table into csv file is
bcp "SELECT...
|
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 another user can access the same table and all hell can break loose.
My question is this :
If I surround the SQL code using all my inserts and updates with transactions will it guarantee that data will not be corrupted?
eg.
BEGIN...
|
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 there are, it crashes.
There are currently 6 columns, and I only want 4. How do I remove the last two (discount and date)?
Here is a link: http://www.jaredmoore.com/tablesorter/docs/salestable.html
Here is some jquery js that I think...
|
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 using php and jquery through a mysql database will not empty the td elements. There is a table underneath the button in the initial html. if you click on a box in the table, it will empty. the same does not happen for the table that is generated by...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |