简体   繁体   中英

mysql Workbench insert default

I'm using the Inserts tab in mysql wb. If I don't specify any value it just inserts NULL and not the value when exporting.

INSERT INTO foo(foo1, foo2, foo3) VALUES (NULL, "concrete", NULL)

instead it should use the default value where not specified, is that possible with workbench?

INSERT INTO foo(foo2) VALUES ("concrete")

or

INSERT INTO foo(foo1, foo2, foo3) VALUES (default1, "concrete", default3)

In MySQL, you can use the DEFAULT keyword. As explained in the 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.

So, try this:

INSERT INTO foo(foo1, foo2, foo3)
    VALUES (DEFAULT, 'concrete', DEFAULT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM