Auto Increment nvarchar Column in Sql Server 2008
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