Click to See Complete Forum and Search --> : mysql INSERT default value


J0kerz
07-23-2009, 11:44 AM
Hey guys,

I was wondering if there is a way to set the value in an INSERT statement, all to default except from the first value without having to write "DEFAULT" in each field.

Example: My table have 5 columns.



$query = "INSERT INTO test VALUES('username',DEFAULT,DEFAULT,DEFAULT,DEFAULT)";



I have multiple table in my DB, and I dont want to go edit the mysql statement everytime i add/remove a column in a table.

I thought of something that would count the column in a table and then generate a statement with the desire number of "DEFAULT" but I am sure there is a simple way...

Thanks guys! :D

Nedals
07-23-2009, 12:06 PM
Define the columns you wish to set, the others will default automatically

$query = "INSERT INTO test (username) VALUES ('username')";

J0kerz
07-23-2009, 12:22 PM
That was fast! Thanks!