There are a few methods available to the Sybase Transact-SQL developer who needs to obtain the next primary key for the next row to be inserted. If the primary column is an identity column then the next_identity function can be used. The proper syntax is:
SELECT next_identity( "TABLE_NAME" )
If however you have not used the identity column then you can obtain the next ID to be used for INT type columns by getting the highest ID currenlty being used than adding 1 to it. This is done by using the isnull and MAX functions.
SELECT isnull( MAX(ID), 0 ) + 1 FROM TABLE_NAME
Comments & Questions
Add Your Comment