Reputation: 655
Does anyone know how to specify the format for an identity column in sql server. My identity column is also a primary key.
THe expected format is like:
1000 1 ------------- aaa
1000 2 ------------- bbb
1000 3 ------------- ccc
1000 12346 ------- ddd
The identity column is ID_cli and the 1000 needs to be constant
Upvotes: 0
Views: 763
Reputation: 3466
Here is the syntax:
create table tablename (ID_cli int identity(100,1),
AdditionalId as '0001'+Cast(ID as Varchar(10)))
Here Additional Id column will have ID values always prefixed with 0001.
IDENTITY [ (seed , increment) ]
seed:Is the value that is used for the very first row loaded into the table.
increment: Is the incremental value that is added to the identity value of the previous row that was loaded.
Upvotes: 1
Reputation: 96552
You cannot use just an identity for your purposes. You will need to do a custom solution. I can suggest that you have a column with the identity and a computed column that appends the "1000 " to is.
Upvotes: 0