Is it possible to return the newly created value in the identity column
after inserting one row into a table? Will it always be the maximum value in
the table?
Thanks,
Boris Zakharin
Thanks,
Boris Zakharin
insert into table1 (cc) values('cc')
select scope_identity()"
Vadim Rapp
----------------------------------------
Vadim Rapp Consulting
SQL, Access, VB Solutions
847-685-9073
SCOPE_IDENTITY() will return the last identity value that has been inserted
in this scope.
This isn't at all guaranteed to be the maximum value.
1) The increment for the identity can be negative.
2) You can insert rows with different values in the identity column with SET
IDENTITY_INSERT <table name> ON
3) You can reset the seed (starting point) for the identity column with DBCC
CHECK_IDENT()
--
Jacco Schalkwijk MCDBA, MCSD, MCSE
Database Administrator
Eurostop Ltd.
Quote:> Is it possible to return the newly created value in the identity column
> after inserting one row into a table? Will it always be the maximum value
in
> the table?
> Thanks,
> Boris Zakharin
1. Getting the value of an IDENTITY column after an INSERT query
Does anybody know of a way to obtain the the value of an IDENTITY column
using ODBC/RDO after an INSERT query has been performed.
I can issue another SELECT MAX(fieldname) query but that method does not
hold up too well under multi-user access.
Any help would be appreciated.
Enrique Travieso
3. getting identity value after insert
4. DTS Package fails when scheduled on server as SQL Server Agent job
5. Getting IDENTITY value of a row that was just INSERTED
7. Getting the identity value of a newly inserted row
9. Getting IDENTITY value BEFORE an insert(?!)
10. Getting Identity Value on Insert
11. Getting Back Identity column value on Insert using RDS
12. Getting IDENTITY value of newly inserted row
13. Getting the value of an autoincrement or identity field during an sql insert