Extract table data to another table automatically in MYSQL [closed]

0

I have a field called TIME with the data type datetime and this default is CURRENT_TIMESTAMP .

The result when I enter a record comes out in this way 2017-12-20 09:45:00 but what I want is that in another table I save only the specific time.

Is there any way to solve this problem?

Note: Try using only the time data type but it does not accept the CURRENT_TIMESTAMP

    
asked by Granedoy 20.12.2017 в 15:32
source

2 answers

1

I have solved the problem by taking the idea of Bruno Sosa.

In MySQL they should go to triggers, then create the name of the trigger, select the table, in time place before and in insert event.

In definition, place this code:

IF NEW.Hora = '0000-00-00 00:00:00' THEN
SET NEW.HoraX =CURRENT_TIME();
END IF

And it automatically saves me only the time.

    
answered by 20.12.2017 / 16:43
source
2

You could create a TRIGGER which is a trigger, which means that this code that you write in the trigger will be executed after an X event that you are going to specify in this case is AFTER INSERT,

DELIMITER $$

CREATE TRIGGER nombre_del_trigger 
AFTER INSERT ON 'nombreDeTabla1' for each row
begin
INSERT INTO nombreDeTabla@ (Kind, Type, Sno, Status)
Values (new.Kind, new.Type, new.Sno, 'Available');
END$$

DELIMITER ;

To get the data that comes in the insert with the full time you must put new.MasElNombreDeLaColumna // and to stay alone with the date without the time, you can perform a substring you know that the dates will have 10 characters after that is already hour

    
answered by 20.12.2017 в 15:45