473,387 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Identity Block Reserved For Inserts Issue - Are you good?

Rob
Hi all,

I have a bit of a complicated question, hope we have an SQL guru out there
that can help us solve this killer problem.

Due to the size of SQL Database we have (largest in the US), we try to
pre-process large data files in IO until we are ready to insert directly into
the database via BCP (quick, no constraints, no mess... well um that's the
problem)

Because we need to get all the linking before we BCP, we find the current
identity value, push the value up past the number of inserts we are going to
push in from BCP. We then take the block of identities and insert them into
the identity column in our files.

Our problem is that sometimes, the identities from the block somehow get
used or were used by a competing process that uses only automated identity
inserts by SQL.

Why? It really sucks...

Here is a simple example:

Row in the file before "reserving" a block of identities:
Identity|projectid|memberno|name
|313|100|Bob
|313|200|Jane
|313|234|Larry

We then run a sproc like this
Begin Tran
Select top 1 @Member_id_start_value = Ident_Current('Member')
from Member with(TabLockx)

Select @newSeed = @Member_id_start_value + @NumRecords + @range_pad

dbcc checkident(Member, reseed, @newSeed)
Commit Tran

Assuming the current Identity was 1000, and the @range_pad was 5 at the time
of the execution of the sproc:
@Member_id_start_value = 1000
@NumRecords would be 3
@range_pad = 5

making the @newSeed = 1007

We would then take the low value (1000) as the first identity value for the
first record and ++ for each row thereafter resulting in something like this:

identity|projectid|memberno|name
1000|313|100|Bob
1001|313|200|Jane
1002|313|234|Larry

This would then get BCP'd up with "Insert Identity Column" switched on.

There is a lag between getting the block and uploading using BCP of anywhere
from 1 minute to 6 hours.

What happens is that we sometimes find records in the table that have been
assigned an identity in our block.

So, if you got an answer can help us, we'd love to hear it.

BTW - please don't tell me that the problem is because there is a lag
between the time we push the identity past our block range and the insert
from BCP. If that was your answer, you're just un-informed.

Thanks BIG time folks! I know you can do it.

Rob

Nov 1 '06 #1
3 2342

Rob wrote:
Hi all,

I have a bit of a complicated question, hope we have an SQL guru out there
that can help us solve this killer problem.

Due to the size of SQL Database we have (largest in the US), we try to
pre-process large data files in IO until we are ready to insert directly into
the database via BCP (quick, no constraints, no mess... well um that's the
problem)

Because we need to get all the linking before we BCP, we find the current
identity value, push the value up past the number of inserts we are going to
push in from BCP. We then take the block of identities and insert them into
the identity column in our files.

Our problem is that sometimes, the identities from the block somehow get
used or were used by a competing process that uses only automated identity
inserts by SQL.

Why? It really sucks...

Here is a simple example:

Row in the file before "reserving" a block of identities:
Identity|projectid|memberno|name
|313|100|Bob
|313|200|Jane
|313|234|Larry

We then run a sproc like this
Begin Tran
Select top 1 @Member_id_start_value = Ident_Current('Member')
from Member with(TabLockx)

Select @newSeed = @Member_id_start_value + @NumRecords + @range_pad

dbcc checkident(Member, reseed, @newSeed)
Commit Tran

Assuming the current Identity was 1000, and the @range_pad was 5 at the time
of the execution of the sproc:
@Member_id_start_value = 1000
@NumRecords would be 3
@range_pad = 5

making the @newSeed = 1007

We would then take the low value (1000) as the first identity value for the
first record and ++ for each row thereafter resulting in something like this:

identity|projectid|memberno|name
1000|313|100|Bob
1001|313|200|Jane
1002|313|234|Larry

This would then get BCP'd up with "Insert Identity Column" switched on.

There is a lag between getting the block and uploading using BCP of anywhere
from 1 minute to 6 hours.

What happens is that we sometimes find records in the table that have been
assigned an identity in our block.

So, if you got an answer can help us, we'd love to hear it.

BTW - please don't tell me that the problem is because there is a lag
between the time we push the identity past our block range and the insert
from BCP. If that was your answer, you're just un-informed.

Thanks BIG time folks! I know you can do it.

Rob
dbcc checkident (tablename, reseed, 1007) ?

Use lock hints to lock out the competing processes until you're
finished assigning the identities?

Alternatively manage the identity yourself, write a stored proc that
updates the nextID value in a table somewhere with a parameter that
allows you to allocate a number of rows. Use a lock hint to ensure no
other process can read the value before you've updated and force all
applications to use this stored proc. Perhaps do the same with the dbbc
checkident?

Or add a second identity column used soley by your bulk load app, it
doesn't even need to be an identity as you have sole control over it.

Just some ideas off the top of my head.

Nov 1 '06 #2
Well, we don't have the timeline of these inserted records (is their
insertions have been started just before you acquire the lock on the table
or sometime after and after, when? (Before, while or after the BCP?) ) , so
it's hard to tell what's happening here.

Probably that you will hear a lot of comments about the use of
Ident_Current() and dbcc, maybe someone will even suggest you to use the
greatest value in the table Member instead of using Ident_Current();
however, are you sure that it's not the values to be inserted with BCC
themselves that could be wrong?

Finally, I don't understand why you aren't posting this in the
m.p.sqlserver.programming newsgroup.

--
Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)
"Rob" <Ro*@discussions.microsoft.comwrote in message
news:7C**********************************@microsof t.com...
Hi all,

I have a bit of a complicated question, hope we have an SQL guru out there
that can help us solve this killer problem.

Due to the size of SQL Database we have (largest in the US), we try to
pre-process large data files in IO until we are ready to insert directly
into
the database via BCP (quick, no constraints, no mess... well um that's the
problem)

Because we need to get all the linking before we BCP, we find the current
identity value, push the value up past the number of inserts we are going
to
push in from BCP. We then take the block of identities and insert them
into
the identity column in our files.

Our problem is that sometimes, the identities from the block somehow get
used or were used by a competing process that uses only automated identity
inserts by SQL.

Why? It really sucks...

Here is a simple example:

Row in the file before "reserving" a block of identities:
Identity|projectid|memberno|name
|313|100|Bob
|313|200|Jane
|313|234|Larry

We then run a sproc like this
Begin Tran
Select top 1 @Member_id_start_value = Ident_Current('Member')
from Member with(TabLockx)

Select @newSeed = @Member_id_start_value + @NumRecords + @range_pad

dbcc checkident(Member, reseed, @newSeed)
Commit Tran

Assuming the current Identity was 1000, and the @range_pad was 5 at the
time
of the execution of the sproc:
@Member_id_start_value = 1000
@NumRecords would be 3
@range_pad = 5

making the @newSeed = 1007

We would then take the low value (1000) as the first identity value for
the
first record and ++ for each row thereafter resulting in something like
this:

identity|projectid|memberno|name
1000|313|100|Bob
1001|313|200|Jane
1002|313|234|Larry

This would then get BCP'd up with "Insert Identity Column" switched on.

There is a lag between getting the block and uploading using BCP of
anywhere
from 1 minute to 6 hours.

What happens is that we sometimes find records in the table that have been
assigned an identity in our block.

So, if you got an answer can help us, we'd love to hear it.

BTW - please don't tell me that the problem is because there is a lag
between the time we push the identity past our block range and the insert
from BCP. If that was your answer, you're just un-informed.

Thanks BIG time folks! I know you can do it.

Rob

Nov 1 '06 #3
Rob
This post was submitted to the SQL SERVER thread and will no longer be
monitored by me. Sorry for the inconvenience.

Rob

"Rob" wrote:
Hi all,

I have a bit of a complicated question, hope we have an SQL guru out there
that can help us solve this killer problem.

Due to the size of SQL Database we have (largest in the US), we try to
pre-process large data files in IO until we are ready to insert directly into
the database via BCP (quick, no constraints, no mess... well um that's the
problem)

Because we need to get all the linking before we BCP, we find the current
identity value, push the value up past the number of inserts we are going to
push in from BCP. We then take the block of identities and insert them into
the identity column in our files.

Our problem is that sometimes, the identities from the block somehow get
used or were used by a competing process that uses only automated identity
inserts by SQL.

Why? It really sucks...

Here is a simple example:

Row in the file before "reserving" a block of identities:
Identity|projectid|memberno|name
|313|100|Bob
|313|200|Jane
|313|234|Larry

We then run a sproc like this
Begin Tran
Select top 1 @Member_id_start_value = Ident_Current('Member')
from Member with(TabLockx)

Select @newSeed = @Member_id_start_value + @NumRecords + @range_pad

dbcc checkident(Member, reseed, @newSeed)
Commit Tran

Assuming the current Identity was 1000, and the @range_pad was 5 at the time
of the execution of the sproc:
@Member_id_start_value = 1000
@NumRecords would be 3
@range_pad = 5

making the @newSeed = 1007

We would then take the low value (1000) as the first identity value for the
first record and ++ for each row thereafter resulting in something like this:

identity|projectid|memberno|name
1000|313|100|Bob
1001|313|200|Jane
1002|313|234|Larry

This would then get BCP'd up with "Insert Identity Column" switched on.

There is a lag between getting the block and uploading using BCP of anywhere
from 1 minute to 6 hours.

What happens is that we sometimes find records in the table that have been
assigned an identity in our block.

So, if you got an answer can help us, we'd love to hear it.

BTW - please don't tell me that the problem is because there is a lag
between the time we push the identity past our block range and the insert
from BCP. If that was your answer, you're just un-informed.

Thanks BIG time folks! I know you can do it.

Rob
Nov 1 '06 #4

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

Similar topics

1
by: Deepak | last post by:
Hi, I'm using the JDBC API's to access a MS-SQL 2000 DB.I have a manual-commit transaction block involving multiple inserts and updates. One of the step involves retrieving the auto generated...
2
by: Edward | last post by:
SQL 7.0 I have a form in ASP.NET and I want to write the values to the SQL Server tables. The tables are Customer and Address tables. There will be an insert into the Customer table, and I...
3
by: Srini | last post by:
Hello, I would like to know Identity OR sequence which is better?. My requirement is simple. I have a parent table with ID (generated or from sequence) and I want that ID after inserting...
6
by: Who.Really.Really.Cares | last post by:
Hi! I guess this must be a FAQ but I'll give it a try. I've searched the web and usenet archive and found only negative answers. But most of them were dated like 3-4 years back. Hasn't anything...
17
by: Trevor Best | last post by:
I don't know if this has been reported before but it appears to be a bug with Access. If I create two tables both with an identity column then create an insert trigger on table1 that inserts a...
2
by: .Net Newbie | last post by:
Hello, I am somewhat new to .Net and currently working on an intranet site using C# going against SQL Server 2k. I am accepting personal information on a single webform and trying to insert the...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
41
by: pb648174 | last post by:
In a multi-user environment, I would like to get a list of Ids generated, similar to: declare @LastId int select @LastId = Max(Id) From TableMania INSERT INTO TableMania (ColumnA, ColumnB)...
5
by: Veeru71 | last post by:
Given a table with an identity column (GENERATED BY DEFAULT AS IDENTITY), is there any way to get the last generated value by DB2 for the identity column? I can't use identity_val_local() as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.