SQL UPDATE Statement

previous next


The Update Statement

The UPDATE statement is used to modify the data in a table.

Syntax

UPDATE tableName SET columnName = newValue WHERE columnName = someValue;

 


Update one Column in a Row

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

 


Update several Columns in a Row

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

 


Test your SQL Skills

To test your SQL skills click here.


previous next