mysql - SQL Integer Range When Creating Tables -
i'm trying give int in 1 of create statements range of possible values, i.e.
create table site( **siteid int (1,4),** userid int unsigned not null, name varchar(128) unique not null, foreign key (userid) references users(userid), primary key (siteid) );
i forget syntax use ranges, , i'm pretty sure i'm erring when i'm attempting use is. in advance.
author's note: first 2 parts of answer incorrect. thought mysql supported check
constraints , didn't. still doesn't. limit columns simple list of values, use enum
approach @ end of answer. if logic more complicated (range of values, value based on column, etc.), mysql option trigger.
you need check
constraint if it's int
:
create table site ( siteid int, constraint siteid_ck check (siteid in (1, 2, 3, 4)), ... , rest
or:
create table site ( siteid int, constraint siteid_ck check (siteid between 1 , 4), ... , rest
or if can live string siteid then:
create table site ( siteid enum('1', '2', '3', '4'), ... , rest
Comments
Post a Comment