Inserting into Oracle and retrieving the generated sequence ID

Expanding a bit on the answers from @Guru and @Ronnis, you can hide the sequence and make it look more like an auto-increment using a trigger, and have a procedure that does the insert for you and returns the generated ID as an out parameter. create table batch(batchid number, batchname varchar2(30), batchtype char(1), source char(1), … Read more

SQL Server – Auto-incrementation that allows UPDATE statements

A solution to this issue from “Inside Microsoft SQL Server 2008: T-SQL Querying” CREATE TABLE dbo.Sequence( val int IDENTITY (10000, 1) /*Seed this at whatever your current max value is*/ ) GO CREATE PROC dbo.GetSequence @val AS int OUTPUT AS BEGIN TRAN SAVE TRAN S1 INSERT INTO dbo.Sequence DEFAULT VALUES SET @val=SCOPE_IDENTITY() ROLLBACK TRAN S1 … Read more

BULK INSERT with identity (auto-increment) column

Add an id column to the csv file and leave it blank: id,Name,Address ,name1,addr test 1 ,name2,addr test 2 Remove KEEPIDENTITY keyword from query: BULK INSERT Employee FROM ‘path\tempFile.csv ‘ WITH (FIRSTROW = 2,FIELDTERMINATOR = ‘,’ , ROWTERMINATOR = ‘\n’); The id identity field will be auto-incremented. If you assign values to the id field … Read more

SQL Identity (autonumber) is Incremented Even with a Transaction Rollback

If you think about it, the auto-increment number should not be transactional. If other transactions had to wait to see if the auto-number was going to be used or “rolled back”, they would be blocked by the existing transaction using the auto-number. For example, consider my psuedo code below with table A using an auto-number … Read more