lankapala
asked on
create auto number
Hi ,
I need to create auto number for customer number,according same with auto number filed
see below code
Prefix='Cus'
CREATE TABLE dbo.Customers
(
Sequence int IDENTITY(1,1) NOT NULL
, Prefix nchar(1) NOT NULL
, CustomerID AS Prefix + CAST(Sequence + 1000000 as nvarchar(8))
, CONSTRAINT UN_CustomersSequence UNIQUE (Sequence)
, CONSTRAINT PK_Customers PRIMARY KEY (CustomerID)
This is right way or any other proper way?
I need to create auto number for customer number,according same with auto number filed
see below code
Prefix='Cus'
CREATE TABLE dbo.Customers
(
Sequence int IDENTITY(1,1) NOT NULL
, Prefix nchar(1) NOT NULL
, CustomerID AS Prefix + CAST(Sequence + 1000000 as nvarchar(8))
, CONSTRAINT UN_CustomersSequence UNIQUE (Sequence)
, CONSTRAINT PK_Customers PRIMARY KEY (CustomerID)
This is right way or any other proper way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
But im getting following error
Only UNIQUE or PRIMARY KEY constraints can be created on computed columns, while CHECK, FOREIGN KEY, and NOT NULL constraints require that computed columns be persisted.
Only UNIQUE or PRIMARY KEY constraints can be created on computed columns, while CHECK, FOREIGN KEY, and NOT NULL constraints require that computed columns be persisted.
ASKER
??update?
What do you mean with "??update?"
Anyway, how you're doing is correct. It's called Computed Column.