Set data_lancamento
to type TIMESTAMP , and set to Default CURRENT_TIMESTAMP .
Creating an example table:
CREATE TABLE 'testdb'.'Exemplo' (
'id' INT NOT NULL AUTO_INCREMENT ,
'data_lancamento' TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP ,
PRIMARY KEY ('id')
);
This solution is automatic by the bank itself, but if you do not want to change and keep datetime
or date
just put now()
in your SQL like this:
INSERT INTO exemplo (data_lancamento) values (now());
You can also create a Trigger
CREATE TRIGGER 'exemplotrigger' BEFORE INSERT ON 'exemplo'
FOR EACH ROW SET NEW.data_lancamento = NOW();
Note: For Date
or DateTime
there is no same resource of type TIMESTAMP
.
References: