Properly new to SQL - Updating a column

  • I am completely new to SQL Server, and after a recent express install am looking to learn a little.

    I have the studio managment tool. The first thing I am looking to achieve is to update an entire column with the same value.

    Other than pasting it into each line, how can I get it done, is there a gui tool i'm missing or do i need to write a line of code somewhere ?

    Thanks,

    Matt

  • Matt,

    First place you'll want to look is the online help, known as Books Online, for using SELECT, INSERT, UPDATE and DELETE statements.

    In SQL Server Management Studio you'd open a new query window, then switch to which database you want to issue the DML against.

    For example, type the following in the query window, then highlight the statements you want to run and press F5, or the VCR style play button on the toolbar, to execute.

    -- Switch to the database

    USE myDatabase

    GO

    -- Update a column in all rows

    UPDATE myTable

    SET myColumn1 = 'new value'

    GO

    -- Update a column in rows which match specific criteria

    UPDATE myTable

    SET myColumn1 = 'new value'

    WHERE myColumn1 = 'test value'

    GO

    Many good free resources are available such as Books Online and Webcasts from Microsoft.

    One book that might interest you is Microsoft SQL Server 2005: Database Essentials, which is a step by step guide.

    Have fun.

  • Hi

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

    If you want to update all the records then simply dont use any WHERE condition.

    ex:

    UPDATE EMP

    SET SALARY = 0

    If you want to update specific rows then use WHERE condition,.

    ex:

    UPDATE EMP

    SET SALARY = 100

    WHERE EMPID = 10

    check out the below link to get some idea on UPDATES.

    http://www.w3schools.com/Sql/sql_update.asp

    Thanks -- Vj

    http://dotnetvj.blogspot.com

  • Thanks for your help guys. Worked nicely.

    Matt

  • Just wanted to say that Todd, that is very good advise for newbie, I like the way you not only help him with the problem but also gave him tools for the future thats what we like to see:D

    ----------------------------------------------
    Try to learn something about everything and everything about something. - Thomas Henry Huxley

    :w00t:
    Posting Best Practices[/url]
    Numbers / Tally Tables[/url]

    SQL-4-Life

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply