What are you looking for ?
Home » » Customized Identity Column

Customized Identity Column


CREATE TABLE

CREATE TABLE dbo.MyTable
(
ID int NOT NULL IDENTITY (1, 1),
Initial nvarchar(10) NULL
)  ON [PRIMARY]
GO

Adding Data

INSERT INTO MyTable ( Initial) VALUES ('A') ,  ('B'), ('C');

select * from MyTable

Customized Identity

ALTER TABLE MyTable  ADD BarCode AS '0-' + CAST(Id as nvarchar(16)) 

select * from MyTable

Combined Identity

 ALTER TABLE MyTable  ADD PrefixField  as Initial + '-' + CAST(Id as Nvarchar(20))

select * from MyTable

Share this article :

Post a Comment

Flag Counter

Social Profile

 
Copyright x 2011. By Wael Medhat - All Rights Reserved