The UPDATE statement is used to modify the data in a table.
UPDATE tableName SET columnName = newValue WHERE columnName = someValue; |
In this "Books" table:
Title |
Author |
Publisher |
Year |
الدورة الدموية |
إبن النفيس |
دار العلم |
1650 |
Java 2 |
L. Johnston |
Fast Press |
2002 |
Linux and Unix |
J. Sam |
Fast Press |
2004 |
Linux Distributions |
J. Sam |
Fast Press |
2003 |
Operating Systems |
M. Stone |
Coriolis |
2005 |
Web Programming |
K. Yariv |
East Edition |
2006 |
XML Language |
null |
Science Edition |
null |
We want to add the author name to the book having the title "XML Language":
UPDATE Books SET Author = 'M. Salim' WHERE Title = 'XML Language'; |
The result is:
Title |
Author |
Publisher |
Year |
الدورة الدموية |
إبن النفيس |
دار العلم |
1650 |
Java 2 |
L. Johnston |
Fast Press |
2002 |
Linux and Unix |
J. Sam |
Fast Press |
2004 |
Linux Distributions |
J. Sam |
Fast Press |
2003 |
Operating Systems |
M. Stone |
Coriolis |
2005 |
Web Programming |
K. Yariv |
East Edition |
2006 |
XML Language |
M. Salim |
Science Edition |
null |
We want to change the publisher name and add the year of publication to the same book (i.e. the book having the title "XML Language"):
UPDATE Books SET Publisher = 'Knowledge Press', Year = 2000 WHERE Title = 'XML Language'; |
The result is:
Title |
Author |
Publisher |
Year |
الدورة الدموية |
إبن النفيس |
دار العلم |
1650 |
Java 2 |
L. Johnston |
Fast Press |
2002 |
Linux and Unix |
J. Sam |
Fast Press |
2004 |
Linux Distributions |
J. Sam |
Fast Press |
2003 |
Operating Systems |
M. Stone |
Coriolis |
2005 |
Web Programming |
K. Yariv |
East Edition |
2006 |
XML Language |
M. Salim |
Knowledge Press |
2000 |
To test your SQL skills click here.