How To Use Identity On Non-identity Column (with Concurrence)
Aug 1, 2014
I'm working with a third-party database (SQL Server 2005) and the problem here is the following:
- There are a bunch of ETL processes that needs to insert rows on a table (let's call this table T) and at the same time, an ERP (owner of T) is up and running (reading, updating and inserting on T).
- The PK of T is an Integer.
Today all ETL processes uses (select max(ID) + 1 from T) to insert new rows, so just picture the scenario. It is a mess! Everyday they get duplicate key error when 2 or more concurrent processes are trying to insert a row (with the max) at the same time.
Considering that I can't change the PK, what is the best approach to solve this problem?
To sum up:
* I need to have processes in parallel inserting on T
* I can't change anything on T
* The PK is NOT an Identity
View 4 Replies
ADVERTISEMENT
Jun 19, 2008
Hi,
I am having problem in bulk update of a sql server table haning identity column from a datatable( has no identity column) using sqlbulkcopy. I tried several approaches, but it does not show any error nor is the table getting updated. But the identity value seems to getting increased every time.
thanks.
varun
View 6 Replies
View Related
Jan 25, 2015
I have table of three column first column is an ID column. However at creation of the table i have not set this column to auto increment. Then i have copied 50 rows in another table to this table then set the ID column values to zero.
Now I have changed the ID column to auto increment seed=1 increment=1 but the problem is i couldn't figure out how to update this ID column with zero value set to each row with this auto increment values so the ID column would have values from 1-50. Is there a away to do this?
View 6 Replies
View Related
Sep 19, 2005
Ok,I just need to know how to get the last record inserted by the highestIDENTITY number. Even if the computer was rebooted and it was twoweeks ago. (Does not have to do with the session).Any help is appreciated.Thanks,Trint
View 2 Replies
View Related
Aug 12, 2009
when i alter non identity column to identity column using this Query alter table testid alter column test int identity(1,1) then i got this error message Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'identity'.
View 2 Replies
View Related
Jul 9, 2006
While I have learned a lot from this thread I am still basically confused about the issues involved.
.I wanted to INSERT a record in a parent table, get the Identity back and use it in a child table. Seems simple.
To my knowledge, mine would be the only process running that would update these tables. I was told that there is no guarantee, because the OLEDB provider could write the second destination row before the first, that the proper parent-child relationship would be generated as expected. It was recommended that I create my own variable in memory to hold the Identity value and use that in my SSIS package.
1. A simple example SSIS .dts example illustrating the approach of using a variable for identity would be helpful.
2. Suppose I actually had two processes updating these tables, running at the same time. Then it seems the "variable" method will also have its problems. Is there a final solution other than locking the tables involved prior to updating them or doing something crazy like using a GUID for the primary key!
3. We have done the type of parent-child inserts I originally described from t-sql for years without any apparent problems. (Maybe we were just lucky.) Is the entire issue simply a t-sql one or does SSIS add a layer of complexity beyond t-sql that needs to be addressed?
TIA,
Barkingdog
View 10 Replies
View Related
Jun 30, 2006
I want to insert a new record into a table with an Identity field and return the new Identify field value back to the data stream (for later insertion as a foreign key in another table).
What is the most direct way to do this in SSIS?
TIA,
barkingdog
P.S. Or should I pass the identity value back in a variable and not make it part of the data stream?
View 12 Replies
View Related
Nov 8, 2007
I have been trying to get the new sol_id that is added so I can use it in other code, but it is only returning 0. The new record is getting added to the table, but my varaiable myNewSolID is 0 in my response.write(myNewSolID)
I appeaciate any help!
Here is my steored procedure and my code:
ALTER PROCEDURE [dbo].[AddTrackings]
@DropDate datetime,
@Comment nvarchar(100),
@DateEntered datetime,
@EnteredBy nvarchar(50),
@Sol_ID Int OUTPUT
AS
INSERT INTO tblTrackings (DropDate, Comment, DateEntered, EnteredBy)
VALUES (@DropDate,@Comment,@DateEntered,@EnteredBy)
SET @Sol_ID=SCOPE_IDENTITY()
RETURN
Sub ProcessTracking()
Dim myNewSolID As Integer
Dim ConnectStr As String = _
ConfigurationManager.ConnectionStrings("2ConnectionString").ConnectionString
Dim MySQL As String = ""
If Me.chkDropSave.Checked Then
MySQL = "AddTrackings"
Dim MyConn As New SqlConnection(ConnectStr)
Dim Cmd As New SqlCommand(MySQL, MyConn)
Cmd.CommandType = CommandType.StoredProcedure
Dim InsertedInteger As New SqlParameter("@Sol_ID", SqlDbType.Int)
InsertedInteger.Direction = ParameterDirection.Output
Cmd.Parameters.Add(InsertedInteger)
Dim MySqlParamStart As New SqlParameter("@DropDate", SqlDbType.DateTime)
Cmd.Parameters.Add(MySqlParamStart)
MySqlParamStart.Value = Me.BasicDatePickerDropDate.SelectedValue
Dim MySqlParamAmtTo As New SqlParameter("@Comment", SqlDbType.NVarChar, 100)
Cmd.Parameters.Add(MySqlParamAmtTo)
MySqlParamAmtTo.Value = Me.txtComment.Text
Cmd.Parameters.AddWithValue("@DateEntered", Now())
Cmd.Parameters.AddWithValue("@EnteredBy", Profile.UserName)
Try
MyConn.Open()
myNewSolID = Cmd.ExecuteScalar()Response.Write(myNewSolID)
Catch ex As Exception
Response.Write(ex.Message)
Finally
MyConn.Close()
End Try
Else
End If
End Sub
View 8 Replies
View Related
Apr 24, 2008
Hi to all, Using sql query i want to check whether the column is Identity column or not? Please members reply me.
View 2 Replies
View Related
Mar 27, 2001
Having an identity column in target table, how do I use SQL 7 DTS ?
In Import wizard, I chose 'ignore' in source, checked Enable Indenity Insert - DTS failed with a msg like - a column cannot have NULL...
In DTS package, had Fast load and Enable Indenity checked - no luck !
Unchecked Enable identity, do luck.
What would be the standard procs for this since this sounds like a very common
senario.
What I am expecting is to insert from source and SQL would take care identity column automatically.
Appreciate your help very much !
-Ivan
--------------------------------------------------------------------------------
View 1 Replies
View Related
Sep 17, 2001
I want to know how to reset the identiy column when i delete a row from the existing table.
Example:
I have a table a with id (identity incr value 1) and name
I have 10 records inserted into it.,which would be from 1...thru...10 i delete a record say 5 then i have 1,2,3,4,6,7,8,9,10, now i want them to be rearranged to systamatic order like 1,2,3,4,5,6,7,8,9 how can i do this.
Thanks in advance,
Shaheen
"God Bless America"
View 2 Replies
View Related
Feb 29, 2000
I have a table that has a field that will not accept null values. I was trying to create a new table with a new field that would accept null values. I would then drop the original table and rename the new table. The problem is my key field has the Identity column (Autonumber) turned on. This allows the recordID to be automatically generated. Is there anyway to bypass the Identity Column feature and still keep it there future records? I already tried the "with Nocheck Clause" but does not work.
View 2 Replies
View Related
Nov 11, 1998
How does one bcp data INTO a MS SQL Server table that includes an IDENTITY column from a text file that does NOT include a value for the IDENTITY column? Surely, this must be a common process?
View 3 Replies
View Related
Apr 9, 2006
Kudos to y'all! On most of my tables, I'm using a column of data type numeric and properties set as Identity with no replication. Now I know that it can handle only a length of 9 and obviously not nullable. Now by length of 9, does it mean in bytes or literal digits. If it is, then that would mean that it would reach only up to 999,999,999. What happens then if it reaches that digit?
View 7 Replies
View Related
Feb 9, 2004
How do you insert into a table that has an identity column aset of rows with predefined values for the identity column.
I have tried to Set Identity_insert off and then insert but it didnt work.
any ideas?
View 1 Replies
View Related
Apr 3, 2006
can i add null to identity type column
View 5 Replies
View Related
Mar 18, 2008
Hi frnds
I have a table with two columns eid , ename . eid set identity(1,1).
After inserting 10 rows how can we insert a user defined eid ?
need help
Thanks & Regards
Zakeer
View 2 Replies
View Related
Jul 23, 2005
Hi,I would like a piece of advice.I have 3 foreign keys in a table used as primary keys for this table.Is it useful in that case to have just one identity column that wouldbe used as the unique primary key, thus no need to have 3 primary keys?Advantages vs Drabacks ?Regards
View 7 Replies
View Related
Nov 6, 2006
Hi Everyone:
I am new to Mobile programming. I am now working on a mobile project. I encounter an issue when I sync the data:
cause I can't modify the schema, so I have to use RDA instead of Merge replication on sql server 2005.
However, There is an identiy column on each table I will pull them down to local mobile database. And I will use those identity columns to connect tables. Even worse, the photo's new name will combine the photoID which is an identity column. There would an issue, if i sync data, the photoID would be same on different local mobile databases. And there would be generate same identity value when users sync data.
How can I avoid those issues? If you have any good ideas, please help me out so that I can meet the project deadline.
Thanks
James
View 11 Replies
View Related
Sep 13, 2007
Hi,
I need to turn off Identity of a column which already has records, i have tried SET IDENTITY_INSERT TableName OFF but it is not working. can any one please help me.
View 3 Replies
View Related
Oct 3, 2007
Consider a table by name "IdentityExample" having only one column "ID_Column" which is an identity column. Now How will you insert a row into this table???
Table Structure
----------------------
CREATE TABLE IdentityExample
(
ID_Column int IDENTITY(1,1)
)
View 4 Replies
View Related
Nov 11, 2006
Hi, Can anyone write me a script, how can I reset identity on column? ( I want to start records from 1 again)
Thanks, radco
View 1 Replies
View Related
Jan 22, 2007
What is the different between Primary key and Identity Column? and when should I them?
(Im just a beginner with databases...)
View 1 Replies
View Related
Aug 3, 2007
For some reason my primary key, identity column skipped a couple of numbers. It went from row 734 to 736, 737, 739
Any ideas why this would happen?
thanks
View 3 Replies
View Related
Sep 18, 2007
Please excuse my ignorance. I've researched this and it appears I am asking to do something that is ridiculous, so please let me know what is wrong with my design (or my brain). I'd like to update an ID number in a table. It is an identity column. In my solution I'm adding a lot of new entries into my table and deleting old ones. Call me anal, but It's driving me nuts that my ID numbers are growing so large so quickly and that I have so many unused ID's. If you were to look over my data ID's they would be something like 1,3,45,78,88,89,103,140,219. What I'm trying to do is renumber my data so that my data currently at say ID# 1067 can be moved to the unused ID#2, etc. So I either need a way to update an Identity column...or I need a way find the lowest unused number among a list of ID's. So is there anyway to achieve what I am trying to do? I see this guy had my same OCD issue (without a solution) :-(
View 3 Replies
View Related
Nov 16, 2007
For an ASP.net project, I have had a DropDownList with a static ArrayList.The ArrayList will be defined from a View, where there is no Identity PK.
I also have used cbxDropDownListName.SelectedIndex to add new data toa table, where an Indetity PK is used to reference the ArrayList.
I am wondering how can I add an identity PK to my view?
TIA,Jeffrey
View 1 Replies
View Related
Jan 15, 2008
Hi.
I had searched the problem regarding the identity column. I am not sure how to solve it in another way round.
As you see, when i tried to set column, ID to be auto identity increment, 1 and identity seed, 1.
When i add a record, it work, it show correctly from ID 1,2,3,4,5 and go on.
When i delete a record ID 5, i add another record, it does not display correctly. etc, ID 1,2,3,4,6,7, ID 5 was missing because it was removed.
Can it possible to replace ID5 with new record after i delete ID5, as i want ID number to work this way, etc from ID 1,2,3,4,5,6 and go on without missing ID?
Is there any way to keep in order from ID 1,2,3,4,5,6 ?
View 4 Replies
View Related
Apr 29, 2008
hi,
As i have created a table with a identity column and now i am using a procedure to insert the values into that table....but when i execute it it gives an err saying err converting varchar data to int and also on the asp.net ......plz help me out for the procedure and the using it with sqlcommand in .net.
create table demo2(id int identity(1,1),name varchar(20))
create procedure sp_demo2
(@id int,@name varchar(20))as begin
insert into demo2(name) values(@name)
set @id=@@identity
end
exec sp_demo2 'j'
thanks,
rajiv
View 3 Replies
View Related
Jun 9, 2004
I am currently using IDENT_CURRENT to return the Id of a new row in SQL 2000, but I am looking for a similar way to do this in SQL 7. Ihave no experience with SQL 7
Anyone remember how they did this ?
View 1 Replies
View Related
May 29, 2006
Got this error:"An explicit value for the identity column in table 'sdk_appsettings' can only be specified when a column list is used and IDENTITY_INSER is on"Any idea?
Also what is MAX in nvarchar(max)?
View 3 Replies
View Related
May 2, 2001
If there are gaps ( due to deletions ) in indentity column, how do I
resequence the values ? As well as how to reset the last used number ?
Info. is greatly appreciated.
Ivan
View 1 Replies
View Related
May 14, 2001
Is it possible to refresh an identity column so that it re-numbers all columns in order starting with the identity seed without having to drop and recreate the column?
View 2 Replies
View Related
Jun 26, 2001
How to remove identity property from a column throught SQL statement?
View 4 Replies
View Related