Click here to Skip to main content
15,904,817 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
How do I update a mySQL database with  new values, but the unchanged rows should be left as it is and need to update changed rows and need to add new rows if the record is not available.

I am a beginner and Give me a basic idea please
Posted
Comments
Mohibur Rashid 6-Jan-16 0:39am    
Have you tried anything?

1 solution

Not exactly sure what you're asking, seems like 2 answers are required

1) a straight update

see MySQL :: MySQL 5.7 Reference Manual :: 13.2.11 UPDATE Syntax[^] - you do an SQL update with a 'where' clause to make sure only particular rows are updated - since you provide no other information eg table name, schema, cant really help you more on it

2) Another option that may be better is a MySQL INSERT ... ON DUPLICATE KEY UPDATE type of statement per : MySQL :: MySQL 5.7 Reference Manual :: 13.2.5 INSERT Syntax[^]
 
Share this answer
 
Comments
Abdul Rahman BCS 6-Jan-16 1:12am    
Thank you,
the thing I want is I have a table that I insert datas to the table fields from a excel file. all I need is when I update the table with another excel sheet(a sheet that has been changed in only some fields not all the fields changed) it should check the current table and should update only the changed columns.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900