0

I have a table called sp_en and this table has 2 columns: "no" and "value". I want to change "value" of row with "no": 4433 to 1 so I enter the command below:

INSERT INTO sp_en (Say) WHERE no='4433' values ("1");

Error returned is:

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 'where no='4433'(Say) values ("1")' at line 1

What's the problem. All answers will be appreciated...

  • 1
    Did you check the manual? – JdeBP Mar 11 '17 at 11:53
  • check how? Can you give me any clues about the answer? – Konko Mar 11 '17 at 11:54
  • 1
    « Check how? » Er. Use your favourite search engine to find the MySQL reference website. Search for the INSERT command. Check the syntax by reading the definition of the INSERT command vs what you have tried to enter. – roaima Mar 11 '17 at 12:04
  • 1
    @MrLister why? What's strange about that? – terdon Mar 11 '17 at 12:59
  • 1
    @terdon Because in some systems, stored procedures customarily start with sp_. – Mr Lister Mar 11 '17 at 13:59
4

You don't want to insert when the entry you want to modify is already in the table. You probably want to update instead:

UPDATE TABLE sp_en SET Say = 1 WHERE no = 4433;

This will update all rows where the no column has value 4433 and for those rows set Say to 1.

I have assumed integer columns.

0

INSERT syntax is only used for inserting new data into the database. To update or change the value UPDATE syntax is used:

UPDATE TABLE table_name
SET column_name = value
WHERE column_name = value;

In above syntax replace lowercase word with their respective values. Also, column_name used in SET is the one you want to change while the one used in WHERE is the conditional column.

So the query becomes:

UPDATE TABLE so_en
SET my_column = 1
WHERE no = 4433;

Thats all!!!

P.S You can find this answer easily in google. So it would be better if you do some more research. And this question belongs to dba stackexchange

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.