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

Why does select SCOPE_IDENTITY() return a decimal instead of an integer?

In SQL Server, the IDENTITY property can be assigned to tinyint, smallint, int, bigint, decimal(p, 0), or numeric(p, 0) columns. Therefore the SCOPE_IDENTITY function has to return a data type that can encompass all of the above. As previous answers have said, just cast it to int on the server before returning it, then ADO.NET … Read more

SCOPE_IDENTITY() for GUIDs?

You can get the GUID back by using OUTPUT. This works when you’re inserting multiple records also. CREATE TABLE dbo.GuidPk ( ColGuid uniqueidentifier NOT NULL DEFAULT NewSequentialID(), Col2 int NOT NULL ) GO DECLARE @op TABLE ( ColGuid uniqueidentifier ) INSERT INTO dbo.GuidPk ( Col2 ) OUTPUT inserted.ColGuid INTO @op VALUES (1) SELECT * FROM … Read more

techhipbettruvabetnorabahisbahis forumueduseduedueduseduseduseduedueduedus