473,471 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to use check condition in column during insertion

34 New Member
I want to add a check condition to the column. I use the following script

Expand|Select|Wrap|Line Numbers
  1. DROP TABLE IF EXISTS `Customer`;
  2. CREATE TABLE `Customer`
  3. (
  4. `CustomerId` INT UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT
  5. ,`Name` VARCHAR(16) NOT NULL
  6. ,`Sex` CHAR(1) CHECK('M')
  7. ,PRIMARY KEY (`CustomerId`)
  8. );
But when i try to insert wrong data, it inserts
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO Customer(`Name`, `Sex`)
  2. VALUES('John Smith', 'Q');
Jul 19 '09 #1
2 3192
SLauren
60 New Member
Try with ENUM data type as below:
Expand|Select|Wrap|Line Numbers
  1. DROP TABLE IF EXISTS `Customer`;
  2. CREATE TABLE `Customer`
  3. (
  4. `CustomerId` INT UNSIGNED NOT NULL UNIQUE AUTO_INCREMENT
  5. ,`Name` VARCHAR(16) NOT NULL
  6. ,`Sex` ENUM('M', 'F')
  7. ,PRIMARY KEY (`CustomerId`)
  8. );
  9.  
Thanks,
Lauren
Jul 20 '09 #2
rahullko05
34 New Member
thanks a lot..appreciated...its working..!!
Jul 20 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

20
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
6
by: Joshua Weston | last post by:
I am new to C++ and I am very interested in becoming proficient. This post is two-fold. One, I am having problems with this small test program. It is meant to allow user input to control a "@"...
4
by: Wim Roffal | last post by:
Is it possible to make a file insertion conditional? I now have the code '<script type="text/javascript" src="http://www.site.com/showit.js">' And I wondered if it is possible to make this...
6
by: steve lord | last post by:
Greetings all, I have a macro that should add a column to a table if the column doesn't already exist. Using the macro condition, how can I test for whether a specific column name in a specific...
3
by: jr | last post by:
A perplexing one this. I Am trying to design a query or series of queries which will firstly identify a condition. If column A value is less than column B value make column C value =1 , else...
2
by: VMI | last post by:
I'm trying to debug a For loop but I don't want the compiler to break everytime it enters the loop. Is it possible to tell the compiler to break when a condition is met? In other words, if my loop...
0
by: polocar | last post by:
Hi, I have noticed a strange behaviour of CurrencyManager objects in C# (I use Visual Studio 2005 Professional Edition). Suppose that you have a SQL Server database with 2 tables called "Cities"...
20
by: technocraze | last post by:
Hi guys & commnunity experts, Does anyone knw how to go about checking for existing data in an MS Acess table? I have tried out the following code using vb but doesnt seem to work that well? Can...
3
by: cj2 | last post by:
if myodbcreader.hasrows then if myodbcreader("code").trim = "" or myodbcreader("reas").trim = "aVAL" then do something endif endif Is this the appropriate way to test if the code field is...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.