mysql Workbench 插入默认值
mysql Workbench insert default
我在 mysql wb 中使用“插入”选项卡。如果我没有指定任何值,它只会插入 NULL 而不是导出时的值。
INSERT INTO foo(foo1, foo2, foo3) VALUES (NULL, "concrete", NULL)
相反,它应该在未指定的地方使用默认值,workbench可以吗?
INSERT INTO foo(foo2) VALUES ("concrete")
或
INSERT INTO foo(foo1, foo2, foo3) VALUES (default1, "concrete", default3)
在MySQL中,可以使用DEFAULT
关键字。如 documentation 中所述:
Use the keyword DEFAULT to set a column explicitly to its default
value. This makes it easier to write INSERT statements that assign
values to all but a few columns, because it enables you to avoid
writing an incomplete VALUES list that does not include a value for
each column in the table. Otherwise, you would have to write out the
list of column names corresponding to each value in the VALUES list.
You can also use DEFAULT(col_name) as a more general form that can be
used in expressions to produce a given column's default value.
所以,试试这个:
INSERT INTO foo(foo1, foo2, foo3)
VALUES (DEFAULT, 'concrete', DEFAULT);
我在 mysql wb 中使用“插入”选项卡。如果我没有指定任何值,它只会插入 NULL 而不是导出时的值。
INSERT INTO foo(foo1, foo2, foo3) VALUES (NULL, "concrete", NULL)
相反,它应该在未指定的地方使用默认值,workbench可以吗?
INSERT INTO foo(foo2) VALUES ("concrete")
或
INSERT INTO foo(foo1, foo2, foo3) VALUES (default1, "concrete", default3)
在MySQL中,可以使用DEFAULT
关键字。如 documentation 中所述:
Use the keyword DEFAULT to set a column explicitly to its default value. This makes it easier to write INSERT statements that assign values to all but a few columns, because it enables you to avoid writing an incomplete VALUES list that does not include a value for each column in the table. Otherwise, you would have to write out the list of column names corresponding to each value in the VALUES list.
You can also use DEFAULT(col_name) as a more general form that can be used in expressions to produce a given column's default value.
所以,试试这个:
INSERT INTO foo(foo1, foo2, foo3)
VALUES (DEFAULT, 'concrete', DEFAULT);