Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:44:54+00:00 2026-05-16T11:44:54+00:00

Using SQL Server 2008, I have a requirement that email addresses in my user

  • 0

Using SQL Server 2008, I have a requirement that email addresses in my user table must be unique, but email addresses are not required in my app. I’ve tried to make email addresses required, but I just cannot get the customer to budge on this one. What is the best method to create this constraint? If I add a constraint, what does the constraint look like? If I add a before insert trigger, what does that look like?

This application will be running on a multi-server web farm, and there are multiple points of entry. An application-level lock() { } is not a great option. I’m doing a select and verifying that the email doesn’t exist from code right before performing the insert operation to give immediate feedback to the user. However, I would really like a database-level solution here. Just in case.

I’m using an ORM (NHibernate with AutoMapping), so I’d rather not insert or update records with a stored procedure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:44:55+00:00Added an answer on May 16, 2026 at 11:44 am

    Use an unique filtered index:

    create table Foo (
     Id int not null identity(1,1) primary key
     , Name varchar(256) null
     , Address varchar(max) null
     , Email varchar(256) null);
    
    create index ndxFooEmail unique on Foo(Email) 
     where Email is not null;
    

    This is a sure-shot 100% bullet proof way to guarantee uniqueness of an optional value. The uniqueness will be enforced in the database server, your ORM/DAL does not need to worry with it, simply handle the error if the unique constraint is violated rather than try to duplicate the constraint in the ORM/DAL (is not really possible to do it correctly under concurrency).

    See Filtered Index Design Guidelines for more details about SQL Server 2008 filtered indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using SQL Server 2008 and I have a table that has a 'Status'
I'm using SQL Server 2008. I have a database table that looks like this
I'm using sql server 2005/2008 and I have a table that it's PK (rec_index)
Ok I'm using SQL Server 2008 and have a table field of type VARCHAR(MAX)
Using Microsoft SQL server 2008 I have a query that is in need of
I'm using SQL Server 2008 and I have a table with three columns: Length
I am using T/SQL in SQL Server 2008 I have a table MyTable with
I'm using SQL Server 2008. I have a table with x amount of rows.
I'm using SQL Server 2008 R2. I have a source table of data (I_Vendor)
I am using SQL Server 2008. I have a Non-Unique Non-clustered index on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.