26 June 2014

computed columns in sql server



CREATE TABLE dbo.MyTable
(
    Id int identity(100,1) NOT NULL PRIMARY KEY,
    CombinedId AS 'Adi-' + CAST(Id as varchar(16))
    Name varchar(50)
)

Or:

CREATE TABLE dbo.MyTable
(
    Id int NOT NULL PRIMARY KEY,
    PrefixField varchar(16),
    CombinedId AS PrefixField + CAST(Id as varchar(16))
)

No comments:

Post a Comment