Auto Increment nvarchar Column in Sql Server 2008

Feb 4 2013 7:20 AM


create table Customers
(
dbID int identity not null primary key,
CustomerName varchar(100)
)
Go

create function CustomerNumber (@id int) 
returns char(5) 
as 
begin 
return 'C' + right('0000' + convert(varchar(10), @id), 4) 
end
Go

alter table Customers add CustomerNumber as dbo.CustomerNumber(dbID)
Go

INSERT INTO Customers(CustomerName) VALUES ('Name')
INSERT INTO Car(CustomerID) VALUES (SCOPE_IDENTITY())
Go

Answers (1)