Reputation: 28444
What I'm asking is whether when inserting a row in a MySQL database the columns that are null need to be included. For instance, when I use phpMyAdmin to insert a row, it will do something like this:
INSERT INTO table
(
`col1`,
`col2`,
`col3`,
`col4`
)
VALUES
(
'value1',
NULL,
NULL,
'value2'
)
Assuming the fields are null by default, can I remove columns and NULL values from the insert statement?
Upvotes: 0
Views: 63
Reputation:
If the column name is also omitted, yes: the default value1 will be assumed.
1 NULL
is usually - but not always! - the default value for nullable columns. The schema must be consulted to verify this assumption.
Upvotes: 2
Reputation: 263893
by default, when you create column it is nullable (unless you have set NOT NULL
on it). so when you want to insert record for specific columns only, you can omit that column and the values for it are automatically null
.
INSERT INTO table (`col1` ,`col4`)
VALUES ('value1','value2')
Upvotes: 3
Reputation: 16673
you can remove them.
if there is a default value - you will get that instead.
Upvotes: 2