Problem inserting null value in Timestamp on Update CURRENT_TIMESTAMP SQL

-1

When I created the table tb_usuario, I put a field to get the exact date and time when making a record to the table tb_usuario, but when I do an insert, do not take or show the date and time when insert something.

this is the code I use for the insert:

INSERT INTO tb_usuario values (null ,'alias','apellido','nombre','12','tipo doc','nro doc', 'correo','nro cel','puesto','area puesto', null ,'ip','nombre pc')

and this is my table tb_user:

drop table if exists tb_usuario;
create table tb_usuario
    (
cod_usuario INT AUTO_INCREMENT,
alias_usuario VARCHAR (15),
apellidos VARCHAR(50),
nombres VARCHAR(50),
edad INT,
tipo_doc VARCHAR (50),
nro_doc VARCHAR(15),
correo VARCHAR (50),
nro_cel VARCHAR (9),
puesto VARCHAR (50),
area_puesto VARCHAR(50),
fecha_creacion_usuario TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ,
ip_v4 VARCHAR(20),
nombre_pc VARCHAR(30),
PRIMARY KEY(cod_usuario)
);

the bd engine is mysql workbench. What am I doing wrong? Any recommendation?

    
asked by Kevin Marshall 27.08.2018 в 20:19
source

2 answers

2

What happens is that you are stating that when an UPDATE is done, the moment of the time it was made is ironed, you must change it to do it in the INSERT in the following way:

fecha_creacion_usuario TIMESTAMP DEFAULT CURRENT_TIMESTAMP

And if you want that field to register both in the INSERT and in the UPDATE , it would be like this:

fecha_creacion_usuario TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    
answered by 27.08.2018 в 20:24
0

As the name implies, ON UPDATE works when doing an update, which has nothing to do with a INSERT .

If you want me to assign a value to you automatically when doing INSERT , AND the clause is DEFAULT

fecha_creacion_usuario TIMESTAMP DEFAULT CURRENT_TIMESTAMP 

link

    
answered by 27.08.2018 в 20:32