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

  • Home
  • SEARCH
  • 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 236937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:23:07+00:00 2026-05-11T20:23:07+00:00

Consider the following table with a constraint that’s a bit daft but simple enough

  • 0

Consider the following table with a constraint that’s a bit daft but simple enough to demonstrate my point. Note that, to keep things very simple, the constraint’s criteria only involve literal values. The column ID only exists because a table must have at least one column (!!) but that column is not involved in the constraint. While a little daft (hence the name) this is perfectly legal syntax and similar to adding WHERE 0 = 1 to a SELECT query to ensure it returns zero rows.

(Standard SQL DDL code, will execute in ACE/Jet’s ANSI-92 Query Mode)

CREATE TABLE Test1 
(
   ID INTEGER NOT NULL, 
   CONSTRAINT daft_1 CHECK (5 = NULL)
);

The following INSERT succeeds:

INSERT INTO Test1 (ID) VALUES (1);

This is expected behaviour. The predicate 5 = NULL should evaluate to UNKNOWN. The INSERT is ‘given the benefit of the doubt’ and succeeds. No problem there.

Consider this similar example using the IN operator:

CREATE TABLE Test2 
(
   ID INTEGER NOT NULL, 
   CONSTRAINT daft_2 CHECK (5 IN (0, 1, NULL))
);

The following INSERT fails because the constraint bites:

INSERT INTO Test2 (ID) VALUES (1);

This is unexpected behviour, by me at least. I would expect the 5 IN (0, 1, NULL) to again be evaluated as UNKNOWN and the INSERT to succeed for the same reasons as the first example.

I would expect the logic in the second example to be the same as the following third example:

CREATE TABLE Test3
(
   ID INTEGER NOT NULL, 
   CONSTRAINT daft_3 CHECK((5 = 0) OR (5 = 1) OR (5 = NULL))
);

The following INSERT succeeds:

INSERT INTO Test3 (ID) VALUES (1);

This is expected behaviour.

I’ve tested all three examples on SQL Server and the all work as I expect i.e. all three INSERT statements succeed. In fact, examining the INFORMATION SCHEMA reveals that for the second example SQL Server as ‘helpfully’ (grrr) rewritten the constraint’s clause to replace the IN operator with

((5)=NULL OR (5)=(1) OR (5)=(0))

So, for ACE/Jet, what is ‘broken’ here: the IN operator or the CHECK constraint?

Here’s some VBA code to reproduce the problem using a NULLable column; also demonstrates that dropping the constraint allows the INSERT to succeed:

Sub TestJetInCheck()

  On Error Resume Next
  Kill Environ$("temp") & "\DropMe.mdb"
  On Error GoTo 0

  Dim cat
  Set cat = CreateObject("ADOX.Catalog")

  With cat
    .Create _
        "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=" & _
        Environ$("temp") & "\DropMe.mdb"

    With .ActiveConnection

      Dim Sql As String
      Sql = _
          "CREATE TABLE Test" & vbCr & _
          "(" & vbCr & _
          "   ID INTEGER, " & vbCr & _
          "   CONSTRAINT daft_constraint " & vbCr & _
          "      CHECK (5 IN (0, 1, NULL))" & vbCr & _
          ");"
      .Execute Sql

      Sql = "INSERT INTO Test (ID) VALUES (1);"

      On Error Resume Next
      .Execute Sql
      If Err.Number <> 0 Then
        MsgBox Err.Description
      Else
        MsgBox "{{no error}}"
      End If
      On Error GoTo 0

      .Execute "ALTER TABLE Test DROP CONSTRAINT daft_constraint;"

      On Error Resume Next
      .Execute Sql
      If Err.Number <> 0 Then
        MsgBox Err.Description
      Else
        MsgBox "{{no error}}"
      End If
      On Error GoTo 0

    End With

    Set .ActiveConnection = Nothing
  End With
End Sub

EDIT: I just thought to try this:

SELECT NULL IN (1);
— returns NULL

SELECT 1 IN (NULL)
— returns zero i.e. FALSE

  • 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-11T20:23:08+00:00Added an answer on May 11, 2026 at 8:23 pm

    I can eliminate the CHECK constraint specifically by creating a Validation Rule (@David W. Fenton: sorry, I find SQL DDL and ADO and easier to write than DAO but thanks for the inspiration):

    Sub TestJetInValidationRule()
    
      On Error Resume Next
      Kill Environ$("temp") & "\DropMe.mdb"
      On Error GoTo 0
    
      Dim cat
      Set cat = CreateObject("ADOX.Catalog")
    
      With cat
        .Create _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=" & _
            Environ$("temp") & "\DropMe.mdb"
    
        With .ActiveConnection
    
          Dim Sql As String
          Sql = _
              "CREATE TABLE Test" & vbCr & _
              "(" & vbCr & _
              "   ID INTEGER" & vbCr & _
              ");"
          .Execute Sql
        End With
    
        ' Create Validation Rules
        Dim jeng
        Set jeng = CreateObject("JRO.JetEngine")
        jeng.RefreshCache .ActiveConnection
    
        .Tables("Test").Columns("ID") _
        .Properties("Jet OLEDB:Column Validation Rule").value = _
        "5 IN (0, 1, NULL)"
    
        jeng.RefreshCache .ActiveConnection
    
        With .ActiveConnection
    
          Sql = "INSERT INTO Test (ID) VALUES (1);"
    
          On Error Resume Next
          .Execute Sql
          If Err.Number <> 0 Then
            MsgBox Err.Description
          Else
            MsgBox "{{no error}}"
          End If
          On Error GoTo 0
    
        End With
    
        Set .ActiveConnection = Nothing
      End With
    End Sub
    

    The Validation Rule bites and INSERT fails. Therefore, I suspect the IN clause is behaving unexpectedly. I shall be using nested OR clauses in future!

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

Sidebar

Ask A Question

Stats

  • Questions 161k
  • Answers 161k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What exactly are you trying to test in your application?… May 12, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer About your question about having only one interface implementation. When… May 12, 2026 at 11:49 am
  • Editorial Team
    Editorial Team added an answer You should use an empty string or other unique text… May 12, 2026 at 11:49 am

Related Questions

Consider the following table with a constraint that's a bit daft but simple enough
I've already checked out the question Deleting duplicate records using a temporary table and
Right... this one had me baffled for a while today so maybe one of
I would like to confirm that the following analysis is correct: I am building
Consider the following table structure with data - AdjusterID | CompanyID | FirstName |

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.