ik wil dat NOW() de standaard waarde wordt bij een datetime in mijn database, maar dat lukt mij niet. Ik heb het ingetypt, maar hij maakt er weer 0000-00-00 00:00:00 van. Weet iemand of dit mogelijk is? of moet in in de query NOW() zetten?
@Jonathan: Als ik je goed begrijp wil je iets inserten zonder dat je de datum/tijd opgeeft maar dat mySQL dan automatisch NOW() invult. Volgens mij kan dat niet en kan het alleen maar in de query.
The DEFAULT clause specifies a default value for a column. With one exception, the default value must be a constant; it cannot be a function or an expression. This means, for example, that you cannot set the default for a date column to be the value of a function such as NOW() or CURRENT_DATE. The exception is that you can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP column as of MySQL 4.1.2. See Section 11.3.1.2, “TIMESTAMP Properties as of MySQL 4.1”.
If a column definition includes no explicit DEFAULT value, MySQL determines the default value as described in Section 11.1.4, “Data Type Default Values”.
BLOB and TEXT columns cannot be assigned a default value.
Kortom, een kolom van het type DATE of DATETIME kun je niet met de functie NOW() van een default waarde voorzien. Met een TIMESTAMP kan dat wel, maar dan wordt ook bij een UPDATE-query deze kolom ALTIJD bijgewerkt. Het is maar de vraag of je dat wel wilt, persoonlijk vind ik het een ongewenste situatie dat de database dit zo maar doet. Ik kan een TIMESTAMP dan ook niet anraden.