Update Query..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mihabib
    New Member
    • Sep 2008
    • 2

    Update Query..

    Hello every one:

    I am missing a basic concept here. Any help will be appreciated.

    I have two tables with lot of fields in both, but two common fields. Even they are not the primary keys but ID is unique and distinct in both so it is safe to join table with ID field.

    Let say table A has A.ID and A.DATE fields.
    Table B has B.ID and B.DATE fields.

    I need to update the entire A.DATE field same as B.DATE for corresponding IDs.

    What would be the best solution (APPEND / INSERT / UPDATE) and why? Since I am stuck with basic here, any syntax would be helpful.

    Thanks.

    Habib.
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    You already said it, you need to UPDATE one field with the other. So you don't have a choice but UPDATE. At least the most if you're looking for the most efficient way. Coz you can always go through creating a new table through a SELECT INTO then dropping the current one and renaming the temp table. Too complicated.

    If you don't need to UPDATE the table and instead, you need to create a new TABLE with the updated fields, a SELECT INTO is your choice, but if you have triggers and constraint, it will not kick-in. If you want to enforce triggers and constraints, create the new table and do an INSERT.

    There's no APPEND in SQL SERVER. Only INSERT.

    -- CK

    Comment

    • mihabib
      New Member
      • Sep 2008
      • 2

      #3
      Thanks for the explanation, a simple but very brief. That's what I needed.

      Habib.

      Comment

      Working...