SELECT IDENT_CURRENT ("empty table")

I use

SELECT IDENT_CURRENT('tablename') 

to calculate the next identifier, but for an empty table it returns 1 not 0

how can i get 0 for empty tables

thanks

+4
source share
2 answers

Does your personality begin with 0 or 1? By default, it starts at 1

Take a look

 CREATE TABLE TestIdent(id INT IDENTITY) GO SELECT IDENT_CURRENT('TestIdent') -- 1 CREATE TABLE TestIdent2(id INT IDENTITY(0,1)) GO SELECT IDENT_CURRENT('TestIdent2') -- 0 
+1
source
 SELECT case when count(*) = 0 then 0 else ident_current('Mytable') end from Mytable 
0
source

All Articles