Update salary attribute in MYSQL

Asked

Viewed 87 times

0

I’m having difficulty in the UPDATE function, where I need to make a change of - 10% in the DEPARTMENT Table where the Salario attribute is from the FUNCIONARIO and DNOME DEPARTMENT table I’m trying so:

 UPDATE DEPARTAMENTO,FUNCIONARIO
 SET Salario = Salario - (Salario * 0.10)
 WHERE Dnome = 'Administração'; 

What I want to do is modify the salaries of all employees of the 'administration' department, by taking out 10 percent of each salary.

This gives error 1175. " You are using safe update mode and you tried to update a table whitouth a WHERE that uses a key column . To disable safe mode toggle the option in prefferences --> Editor and Reconnect "

How can I solve?

1 answer

2

This is just a protection set by the editor you are using (maybe Mysql Workbench?)

It is worth noting that you are fiddling with two tables without spelling out the type of join used, the protection may even be appropriate to your case.


Some editors set the option

SET SQL_SAFE_UPDATES = 1;

which is valid for the current connection. This makes attempts to change without indexed columns in the WHERE are refused in order to avoid extensive modifications by accident.

Most common solutions:

  • wear a SET SQL_SAFE_UPDATES = 0; in the current connection

  • change the preferences of the tool used so that it does not activate the protection

  • or even index that column (but only if it is beneficial for the application as a whole)

More details in the manual:

https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html#option_mysql_safe-updates

This reading can help:

What is the difference between INNER JOIN and OUTER JOIN?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.