Errores de uso de palabras clave predeterminadas de MySQL
Pregunta
Cuando intento configurar la fecha predeterminada y la fecha del sistema predeterminada, recibo los siguientes errores:
Consulta MySQL:
create table product_offer_type(object_id INT(19), snapshot_id INT(19), PRIMARY KEY(object_id,snapshot_id), enum_value VARCHAR(64) NOT NULL, external_name VARCHAR(64) NOT NULL, description VARCHAR(255), business_validation INT(1), valid_for_start_date_time DATE DEFAULT '1900-01-10', valid_for_end_date_time DATE DEFAULT '4712-01-01', mutation_date_time DATE SYSDATE, mutation_user VARCHAR(32) DEFAULT 'USER');
Mensaje de error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SYSDATE, mutation_user VARCHAR(32) DEFAULT 'USER')' at line 1
Cualquier puntero sería muy apreciado.
Solución
Si está intentando rastrear el último tiempo de modificación de la fila, generalmente uso algo como
mutation_date_time timestamp default current_timestamp, al actualizar current_timestamp
Es posible que necesite una ligera modificación si realmente desea Fecha y no marca de tiempo.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow