Shantanu Gupta
Shantanu Gupta

Reputation: 21198

Can we use "if else" in "Check" constraint in sql server

Can i use if else under a check constraint.

Can i use check constraint using a variable

need xplanation with eg.

Upvotes: 1

Views: 1073

Answers (2)

Cade Roux
Cade Roux

Reputation: 89671

You cannot use IF/ELSE, but you can use inline conditionals: CASE WHEN

Upvotes: 2

Tom H
Tom H

Reputation: 47464

Your question is a bit vague. What are you trying to do with the IF...ELSE? Check constraints aren't processed code, they're part of the table definition - there is no control flow and no variables. You can use a user-defined function in check constraints, which may be what you're after, but it's hard to tell from your question.

Upvotes: 3

Related Questions