Error updating a table. (Duplicate key)

2

Good. When doing the update I get error .. Yes I already have a record in the table with those values, but when changing the type should not let me do?

    
asked by anonymous 24.02.2016 / 09:55

1 answer

2
  

Yes, I already have a record in the table with those values, but when changing   the guy should not let me do it?

No, what you have to do is use a Where , that is.

Update Falta_Licao
set Tipo = 1,
Descricao = ''
where Id_Turma = 1
and Id_Disciplina 1
and Licao = 1
and Id_Aluno = 3;

Virtually your table has both fields that you can change without any problem, even without specifying Where are the Type and the description, but if you try to make an update by changing the primary keys of your table may already be have a record with the keys you are reporting,.

See that the primary key of your table is composed of 4 fields, if the combination of these fields already exists you will get this error.

If you need to update in these fields the ideal is to have a unique key to table, that is, to create a Id_Falta_Licao as the primary key, so you could change any field without problem.

    
24.02.2016 / 12:07