Tuesday, June 3

List of tables having 'identity' column

How to get the list of tables with identity column?

ASE 12.5.x, provides a function next_identity(), you can use this function to list the tables
having identity column.
Actually, this function returns, the next possible value for the identity column in a table.

So, to get the list of tables which contains a identity column, our logic is simple,
check the next identity value for each of the tables in database, and if NULL, that means
table does not contain any identity column, else it does.

--#List the table names, which has identity column.
select name from sysobjects where type = 'U' and next_identity(name) != NULL

--#List the table names, which has identity column, along with the next possible identity value.
select name, next_identity(name)
from sysobjects
where type = 'U' and next_identity(name) != NULL




Related Posts :
1. How to get list of identity columns along with table names.

0 comments:





Disclaimer :
Unless, otherwise mentioned, TF's SQL tips/tricks are for Sybase ASE 12.5.x