Quantcast
Channel: Forum Getting started with SQL Server
Viewing all articles
Browse latest Browse all 7129

Can we make Computed Column as primary key If possible than How?

$
0
0

I've this table here. I;mtring to make computed key as primary key

I can't do it. Is it possible to make computed key a primary key

CREATE TABLE [dbo].[tbltest](
    [menuCode] [varchar](150) NOT NULL,
    [moduleCode] [varchar](150) NULL,
    [menuName] [varchar](150) NULL,
    [menuSource] [nvarchar](500) NULL,
    [active] [bit] NULL,
    [ParentCode] AS moduleCode + '-' + menuCode NOT NULL Primary key,
)

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.


Viewing all articles
Browse latest Browse all 7129

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>