Update statement

Posted on 2007-08-05
Last Modified: 2010-03-19
Hello all,

I have a field in my database called
'number' and contains integer values.
How can I run an sql statement and add 15
to all the records?

For example:
I would like to change this:   [itemID], [Name], [Number]
                                              [221], [John White], [1000]
to this:
 [221], [John White], [1015]

So, what it should do is increase the value of 'number' by 15 for all the records in my table.

Question by:nectarios777
    LVL 33

    Expert Comment

    try this

    update yourtablename set Number = Number + 15
    LVL 33

    Accepted Solution

    Please note it will update ALL records!!!
    If this is what you want, then proceed.

    To update only certain records, you should do it with a WHERE clause.

    update yourtablename set Number = Number + 15 where ItemID = 221
    LVL 1

    Author Comment


    thanks for your answer.
    Is there a way to update with random numbers instead of fixed values
    such as 15?
    LVL 33

    Expert Comment

    I would suggest you post a new question to address this.


    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
    Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now