Home Forums SQL Server 2005 T-SQL (SS2K5) Update a record with a validation from other table RE: Update a record with a validation from other table

  • It hurts to love someone and not to be loved in return, but it hurts even more to have an UPDATE without a WHERE.

    Try this example:

    CREATE TABLE CustomerCredit(

    CustomerNumber int,

    CreditLimit decimal(10,2)

    );

    INSERT INTO CustomerCredit

    VALUES

    (1, 1235.46),

    (2, 35.46),

    (3, 199.99),

    (4, 222.22),

    (5, 100.00);

    SELECT * FROM CustomerCredit;

    DECLARE @CreditLimit decimal(10,2) = 999.99;

    BEGIN TRAN; --Make it safe

    UPDATE CustomerCredit

    Set CreditLimit = @CreditLimit;

    SELECT * FROM CustomerCredit;

    ROLLBACK TRAN; --Undo the changes

    --DROP TABLE CustomerCredit;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2