Reply to Re: Equivalent to SQL Anywhere GET_IDENTITY?

Your name:

Reply:


Posted by Robert Klemme on 11/28/06 15:16

On 28.11.2006 00:29, Jim C wrote:
> Is there an equivalent in mssql to SQL Anywhere's GET_IDENTITY which
> reserves the next autoinc value for a table? Yes I know about
> @@Identity and SCOPE_IDENTITY. I need to get the next autoinc value
> _before_ I insert the record due to the way the existing application
> works.
>
> I've seen DBCC CHECKIDENT mentioned but that seems kludgy to me.

You do not post where you need that information. If your insert is in a
stored procedure then SCOPE_IDENTITY after the fact should work.

If for some other reasons you really need the value beforehand, you can
emulate an Oracle sequence

-- test script
create table counter (
cnt int identity(1,1) primary key clustered
)

insert into counter default values
print 'ident: ' + cast(scope_identity() as varchar)
-- optional: truncate table counter

insert into counter default values
print 'ident: ' + cast(scope_identity() as varchar)
-- optional: truncate table counter

drop table counter


The you can pull identity values from that table and use them for the
insert.

Kind regards

robert

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация