Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a row without any values so that all columns assume their default value?

Tags:

php

mysql

I need to do something simple - insert a row into MySQL (with PHP) but without values. The MySQL table will already have the default values it needs, so I don't need to insert any values. How would the insert statement look without values to insert?

like image 820
Phillip Avatar asked Aug 16 '11 10:08

Phillip


People also ask

What is the default value of column for which no default value is defined?

If a data type specification includes no explicit DEFAULT value, MySQL determines the default value as follows: If the column can take NULL as a value, the column is defined with an explicit DEFAULT NULL clause. If the column cannot take NULL as a value, MySQL defines the column with no explicit DEFAULT clause.

What clause allows you to specify a default value for a column?

Use the DEFAULT clause in the CREATE TABLE statement to specify the default value for the database server to insert into a column when no explicit value for the column is specified. This syntax fragment is part of the Column definition.

How do you add values to a specific row?

To insert a row into a table, you need to specify three things: First, the table, which you want to insert a new row, in the INSERT INTO clause. Second, a comma-separated list of columns in the table surrounded by parentheses. Third, a comma-separated list of values surrounded by parentheses in the VALUES clause.

Is it mandatory to insert values in every column of the table?

It is not necessary to insert the value in each column because there always a default value is inserted by the server “NULL”.


1 Answers

INSERT INTO my_table VALUES () 
like image 184
nobody Avatar answered Sep 19 '22 11:09

nobody