开发者

mysql insert command with a where clause

开发者 https://www.devze.com 2023-01-20 08:48 出处:网络
im trying to insert data into a particular row in the database, but i mysql is saying this is an error:

im trying to insert data into a particular row in the database, but i mysql is saying this is an error:

INSERT INTO开发者_StackOverflow user (rep, course) VALUES('5', 'computer science') WHERE user='2'


UPDATE user 
   SET rep = '5', course = 'computer science' 
 WHERE user = '2'

Link to docs.


You might want to UPDATE instead,

UPDATE user set rep='5', course='computer science' WHERE user='2'


INSERT statement should not come with WHERE clause.


INSERT statement can not be used with WHERE clause because you are going to insert a new row using INSERT so how could you check any condition over the row which even doesn't exits ?

That's the main reason you can't use WHERE clause with INSERT statement....

use: UPDATE table-name SET column=val WHERE some cont

Command if you need to update existing row....

0

精彩评论

暂无评论...
验证码 换一张
取 消