[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
SqlUpdate

(SQL) UPDATE

Updates existing records in a table in a database matching the required condition.

UPDATE tablename
SET Field1 = 'Value1', Field2 = 'Value2', ...
WHERE Condition
LIMIT MaxRecordsToChange


For example:
-- A person that changed her last name by marriage
UPDATE Persons
  SET LastName = 'Flintstone '
WHERE 
  FirstName = 'Wilma' AND LastName = 'Dinobush'


Value should be in quotes if it is a non-numerical data type, and not in quotes if it isn't. If you only want to change X number of records, use the LIMIT clause for that. This can be a good security mechanism if you know the condition should only ever change 1 item - even if someone does an exploit that would potentially update all items or other items, damage can be limited.

Note that the value can be a function of the existing value. This is useful for applying changes where the data changes regularly and could change between the data being obtained and the proccessed data being updated (e.g. in a stock control system).

Code links

  •  ?SET
  •  ?WHERE


last edited (November 6, 2006) by bilderbikkel, Number of views: 4340, Current Rev: 8 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.