How to create a check constraint or something similar to verify one or another but not both fields are not null in a create statement

I am trying to use something like a CHECK or an OR statement in a constraint within a table create statement. The objective is to create a condition that either one field or another may be null but not both. Such as   (Field_1 = NULL and Field_2 = NOT NULL) OR (Field_1 = NOT NULL and Field_2 = NULL) But not both

Can someone suggest the SQL to d this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
You can do something like this...

(field_1 is null and Field_2 is not null) or (field_1 is not null and Field_2 is null)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chonabrahamAuthor Commented:
where does this statement go in a CREATE TABLE statement?
Saurabh Singh TeotiaCommented:
If you are trying to create table then probably i will create a index or primary key that both the columns can't be blank and that way will control the same...

Refer to link Here for the same...
chonabrahamAuthor Commented:
What is the structure for creating the index using (field_1 is null and Field_2 is not null) or (field_1 is not null and Field_2 is null)?
Saurabh Singh TeotiaCommented:
On this link...refer to option of filter index..where it says you can give your where criteria in Index which is the same thing what you are looking for...

SQL Index
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.