1

I would like create a unique constraint which specifies that for an ID and BriefID there should be a Unique Name.

eg. the following would not be allowed because of the constraint.

ID   BriefID   Name
12    32        first
12    32        first

the table structure is as follows.

 PK ID                   int    
    Name                 nvarchar(50)   
 FK BriefID              int    
    StatusID             int    
    StartDate            datetimeoffset(7)  
    EndDate              datetime   
    FrequencyID          int    
    MaxArticleDisplay    int    
    LastDateAlertSent    datetime

2 Answers 2

3

How about

ALTER TABLE dbo.YourTable
ADD CONSTRAINT UC_ID_BriefID UNIQUE(ID, BriefID, Name)

With this, you could not insert these two rows you mentioned in your question. Trying to insert the second row would cause a constraint violation and would not succeed.

Sign up to request clarification or add additional context in comments.

Comments

1

You can achieve this with a unique index:

CREATE UNIQUE NONCLUSTERED INDEX [UIX_TABLENAME_001] ON [TABLENAME]
(
    ID,
    BriefID,
    Name
)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.