Results 1 to 6 of 6
  1. #1
    hansdbase is offline Advanced Beginner
    Windows 11 Access 2021
    Join Date
    Nov 2022
    Posts
    33

    CheckConstraint Not working


    I put in a check constraint that only one row has the id equal to another column in the table. I created a function that included a subquery that counted the number of times in the table there was a row that had the id column equal to another particular column. Where it equals 1, all is good with the check constraint. Otherwise of course it shouldn't work. But I can't seem to get it to work right. When the first row is the row that has the equal values id=1 and the comparsion column in the same row equals 1, and no other columns have the id equal to the comparison column, it seems to work. But if I try to change it up and have for instance the first row not have this attribute but the second row for instance where the id =2 and the comparison =2, it does not work. It gives me an error that the check constraint failed. What am I missing here on how these check constraints work? Thanks.

  2. #2
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    Are you able to upload a copy of the database?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  3. #3
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  4. #4
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,044
    If you want a unique combination of values in 2 columns of the same table, I would use a unique index on the two columns

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    Think it would be a good idea if you show the code to your function since that would appear to be where the problem is

  6. #6
    CarlettoFed is online now Competent Performer
    Windows 7 64bit Access 2013 32bit
    Join Date
    Dec 2019
    Posts
    257
    Maybe if you attach a sample file it would be easier to help you.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 01-27-2020, 09:49 AM
  2. Replies: 2
    Last Post: 05-14-2017, 10:07 AM
  3. Working query stops working after importing
    By Abacus1234 in forum Import/Export Data
    Replies: 3
    Last Post: 10-25-2015, 09:12 PM
  4. Replies: 1
    Last Post: 12-27-2014, 12:38 PM
  5. Replies: 3
    Last Post: 01-29-2013, 04:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums