Update table data value

  • Dear Greater SQL Intellect,

    Is there a way to update table data values.

    I have this table:

    CREATE TABLE ups_data

    (UPS_Numberdecimal(2,1) NULL,

    UPS_Modelvarchar(22)NULL,

    Free_InputsintNULL,

    Taken_Inputs_Sourcevarchar(19)NULL,

    Attached_Devicevarchar(38)NULL,

    Power_Ratingvarchar(21)NULL,

    Model_Service_Tagvarchar(30)NULL)

    I want to change the Model_Service_Tag data value from varchar(30) to varchar(50).

    Is there a better way to go about this than drop the table -> make change -> create the table?

    Perhaps I'm misunderstanding how to use the UPDATE transact sql command. From my gatherings, it seems to update the imported data...rather than the table data values.

    Thanks.

    Regards,

    Mike G.

    Seattle, WA

  • Check out ALTER TABLE in BOL.

    Wayne
    Microsoft Certified Master: SQL Server 2008
    Author - SQL Server T-SQL Recipes


    If you can't explain to another person how the code that you're copying from the internet works, then DON'T USE IT on a production system! After all, you will be the one supporting it!
    Links:
    For better assistance in answering your questions
    Performance Problems
    Common date/time routines
    Understanding and Using APPLY Part 1 & Part 2

  • Like you said, UPDATE is used to update values within the table - it is a DML (Data Manipulation Language) command. What you want to do is modify the structure of the table -- you need to use DDL (Data Definition Language) commands.

    Try the following:

    ALTER TABLE ups_data

    ALTER COLUMN Model_Service_Tag varchar(50)

    Note that if the column you're changing is a primary key or has a constraint on it, you may have to drop any relationships or constraints that may exist before you make the change.

    Also, if you're making the column SMALLER (e.g., to varchar(10) in your example), you could truncate data.

    Rob Schripsema
    Propack, Inc.

  • Hello,

    And there it is...

    DML and DDL - it all makes sense now.

    My apologies for such a novice inquiry...

    Thank you for your replies.

    Regards,

    Mike G.

    Seattle, WA

  • No apologies necessary. We were all newbies once...

    Rob Schripsema
    Propack, Inc.

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

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