Como saber o valor de um campo identado
Senhores, estou usando o Delphi 7, com MSSQL SERVER (MSDE) e ADO.
Tenho o seguinte problema: Gostaria de ao acabar de incluir um registo em uma tabela (insert - post) saber qual o valor de um campo identity deste registro, pois preciso emitir, na hora, um relatorio informando este dado. Será usando o comando ´Select @@identity´ ?? E se por uma terrível azar outro usuário estiver fazendo um outra inclusão ?? poderei receber um número errado ??
Agradeço ajuda.
sds
Tenho o seguinte problema: Gostaria de ao acabar de incluir um registo em uma tabela (insert - post) saber qual o valor de um campo identity deste registro, pois preciso emitir, na hora, um relatorio informando este dado. Será usando o comando ´Select @@identity´ ?? E se por uma terrível azar outro usuário estiver fazendo um outra inclusão ?? poderei receber um número errado ??
Agradeço ajuda.
sds
Rounilo
Curtidas 0
Respostas
Rjun
04/04/2005
@@IDENTITY, SCOPE_IDENTITY, and IDENT_CURRENT are similar functions in that they return the last value inserted into the IDENTITY column of a table.
@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
@@IDENTITY and SCOPE_IDENTITY will return the last identity value generated in any table in the current session. However, SCOPE_IDENTITY returns the value only within the current scope; @@IDENTITY is not limited to a specific scope.
IDENT_CURRENT is not limited by scope and session; it is limited to a specified table. IDENT_CURRENT returns the identity value generated for a specific table in any session and any scope.
GOSTEI 0