只需做一个需要多个项目由AJAX重新排序的站点.
Just doing a site which requires multiple items to be reordered by AJAX.
当我在数据库中创建给定对象时,我想在创建时将position列设置为行的主键的值.
When I create a given object in the database, I want to set the position column to the value of the rows' primary key upon creation.
请问我该怎么做?
推荐答案MySQL文档:
DEFAULT子句为列指定默认值.除一个例外,默认值必须为常数;否则为0.它不能是函数或表达式.例如,这意味着您不能将日期列的默认值设置为诸如NOW()或CURRENT_DATE之类的函数的值.唯一的例外是,您可以将CURRENT_TIMESTAMP指定为TIMESTAMP列的默认值.请参见第10.3.1.1节"TIMESTAMP属性".
The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column. See Section 10.3.1.1, "TIMESTAMP Properties".
虽然您可以通过选择获得id值:
You can though obtain the id value on selection instead:
SELECT id, COALESCE(position, id) as position ...更多推荐
MySQL将默认值设置为项目自动增量键
发布评论