php - Constrain when create table mysql failure -


i new php mysql , restrict user input value. example type should m or c not others. therefore use code following create table1 under database hactl.

/**********************************************************************/ /*create database , table*/  create database hactl; create table  hactl.table1(     type varchar(1) not null,     region varchar(50) not null,     country varchar(50) not null,     city varchar(3) not null,     imp decimal(10,2) not null,     exp decimal(10,2) not null,     ts decimal(10,2) not null,     year int(4) not null,     month varchar(3) not null,     constraint chk_hactl check(type in ('m','c') ,                    month in ('jan', 'feb', 'mar',                           'apr', 'may', 'jun',                          'jul', 'aug', 'sep',                          'oct', 'nov', 'dec')                   ) ); 

while when insert new row type = k, still can insert successfuly.

to rescrict other entry, can use enum

create table  hactl.table1( type enum('m','c') not null, region varchar(50) not null, country varchar(50) not null, city varchar(3) not null, imp decimal(10,2) not null, exp decimal(10,2) not null, ts decimal(10,2) not null, year int(4) not null, month enum('jan', 'feb', 'mar',             'apr', 'may', 'jun',            'jul', 'aug', 'sep',            'oct', 'nov', 'dec') not null,  ); 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -