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 8066119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:52:46+00:00 2026-06-05T11:52:46+00:00

Would it be possible to create a database-level restriction to prevent creating a row

  • 0

Would it be possible to create a database-level restriction to prevent creating a row that has a column x INT with a value that already exists and is above 0?

Is there a way to use CONSTRAINT for this purpose?

  • 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-06-05T11:52:47+00:00Added an answer on June 5, 2026 at 11:52 am

    A possible solution is to do the following:

    CREATE TABLE test
    (
        id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
        myfield INT,
        CONSTRAINT check_myfield UNIQUE ( myfield )
    );
    

    Now, the column myfield might be NULL. So when we do the following, there will be a total of 0 errors.

    INSERT INTO `test` VALUES ( '', '1' );
    INSERT INTO `test` VALUES ( '', '0' );
    INSERT INTO `test` VALUES ( '', '5' );
    INSERT INTO `test` VALUES ( '', '7' );
    etc, you get the point...
    

    Each and every row has a unique value in the column myfield, but there is still the possibility to create rows where the value in this particular column is NULL which is almost exactly what I wanted. I wanted all values above 0 unique, this is all above NULL. The beauty of this solution is that it feels more ‘professional’, no unnecessary logic.

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

Sidebar

Related Questions

Is it possible to create a program using AS3 that would allow the user
Is it possible to create a database such that there are 2 tables across
How would you / or is it possible to create an animation in css3
I would know if it is possible to create a ListView with a fixed
Is it possible to create types like e.g. String(20) in scala? The aim would
Possible Duplicate: JavaScript library to create div-style window within page I would like to
Would it be possible to add a new operator to the String class that
I am creating a C++ application the uses a MySQL database. I would like
I want my application to create database in the user's computer. The database would
The geonames database has two models that refer to each other. In a postgres

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.