mysql - Create Table and assign a query as default value to a field -
create table `williamhill` ( `id` varchar(50) null, `nick` varchar(50) null, `password` varchar(50) null default (select default_password person p p.id = id), `colonna 4` varchar(50) null ) collate='latin1_swedish_ci' engine=innodb
how can in mysql? i'm trying assign default value table if no value has been specified during creation of new row.
is possible or should use trigger/procedure?
mysql quite explicit cannot done. begin with, syntax default called default value. value expected.
here how documentation describes this:
the
default
value clause in data type specification indicates default value column. with 1 exception, default value must constant; cannot function or expression.
(the 1 exception current_time
people don't realize function.)
many databases allow function calls here. none -- far know -- allow query expressions. however, can emulated in user-defined function.
the work-around use trigger. looking value in table common use of triggers.
Comments
Post a Comment