sql - Create column which increases from last index -


this question has answer here:

i need generate column invoiceid. , want keep formate of column

inv0000001, inv0000002, . . . . inv0000010, inv0000011, . . , on.  

as can see column increasing last index. how can this.

i'm using sql server 2012.

i have searched, couldn't find, how increase number this.

try using computed column msdn

create table yourtablename (     id int identity (1,1) not null,     invoiceid 'inv'+ right('000000'+cast(id varchar(20)),7) persisted ); 

sqlfiddle demo

for more info on why need make computed column persisted check here


Comments