Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

225
Visualizações
MYSQL History Table

I am using MYSQL with PHP for a Student database.

Whenever I update a Student's info I would like to keep a record of the previous values.

Right now I have a trigger set up to insert the entire update into a history table which is a duplicate of the Students table with a few added columns: Action, and timestamp.

before update
on Students
for each row
INSERT INTO StudentHistory SELECT 'update', NULL, NOW(), d.*
FROM Students AS d WHERE d.ID = NEW.ID;

However, since this table has about 20 fields I'd rather not have that much duplicate data if just one field was updated.

Is there a way to insert only columns that actually changed into the history table?

If not, is there a way to compare the rows in the history table for each student to see which columns actually changed?

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda