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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:14:46+00:00 2026-05-18T02:14:46+00:00

I have a table with check constraint that is ignored by MySQL. I am

  • 0

I have a table with check constraint that is ignored by MySQL. I am using foreign key constraint to achieve the same functionality. Is it OK or if there is something I need to know while I use this method?

CREATE TABLE country (
  code VARCHAR(2) NOT NULL,
  iso_code VARCHAR(3) NOT NULL,
  name VARCHAR(30) NOT NULL,
  status VARCHAR(10) NOT NULL DEFAULT 'ACTIVE',
  PRIMARY KEY  (code),
  CONSTRAINT CK_COUNTRY_STATUS CHECK(status in ('ACTIVE','INACTIVE'))
)ENGINE=InnoDB 

drop table if exists country_status;
CREATE TABLE country_status (status varchar(10) NOT NULL DEFAULT '', PRIMARY KEY (status)) ENGINE=InnoDB ;
insert into country_status VALUES ('ACTIVE') , ('INACTIVE');
alter table country add CONSTRAINT FK_COUNTRY_STATUS FOREIGN KEY (status) REFERENCES country_status (status);

mysql> show create table country\G
*************************** 1. row ***************************
       Table: country
Create Table: CREATE TABLE `country` (
  `code` varchar(2) NOT NULL,
  `iso_code` varchar(3) NOT NULL,
  `name` varchar(30) NOT NULL,
  `status` varchar(10) NOT NULL DEFAULT 'ACTIVE',
  PRIMARY KEY (`code`),
  KEY `FK_COUNTRY_STATUS` (`status`),
  CONSTRAINT `FK_COUNTRY_STATUS` FOREIGN KEY (`status`) REFERENCES `country_status` (`status`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.00 sec)
  • 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-18T02:14:46+00:00Added an answer on May 18, 2026 at 2:14 am

    Use enums. http://dev.mysql.com/doc/refman/5.0/en/enum.html

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

Sidebar

Related Questions

I have an ItemComments table that has one column with a foreign key constraint
I have a table called PX_Child that has a foreign key on PX_Parent. I'd
Hi, I have a table that contains a foreign key value(id). This field is
I have a table with a nullable integer field that is a foreign key.
I have an app that needs to check a database table every minute. The
I'm using SQL Server 2008. I have a database table that looks like this
I am new to the SQL CHECK CONSTRAINT and need something to verify that
i have a table with two foreign keys as composite key. ActivityTbl - (activityNbr(PK),
I have a table where each rows has a check box. This code works
I'm trying to write a simple stock check program, and I have a Table

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.