mmarques
mmarques

Reputation: 655

How to specify sql server identity

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:

ID_cli -------- Name

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

Answers (2)

Sonam
Sonam

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

HLGEM
HLGEM

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

Related Questions