4

As indicated in this post Update all columns from another table?

I need to update a table with 50 columns with values from another table, and then insert new records from a different table (with 50 columns). I really don't want to list 50 name-value pairs (or use the bulk updating syntax here Bulk update of all columns, which SQL Server doesn't seem to like anyway).

So, I can conclude one of the following:

  1. There IS a way after all,
  2. It's ridiculous to have a table with 50 columns, or
  3. Database Admins are masochists.
James Alesi
  • 91
  • 2
  • 5
  • 2
    They're not mutually exclusive - all three could be true. – Michael Green Aug 23 '16 at 10:42
  • 5
    Seems to me the time you wrote asking the question could have been spent copying/pasting those column names and you'd have your update statement. – Molenpad Aug 23 '16 at 10:46
  • Do you really want to trust data modifications to an algorithm that decides which columns match up between two tables? – datagod Aug 23 '16 at 16:55
  • Why not, if the column names are all the same? – James Alesi Aug 24 '16 at 02:29
  • If you need to do this once - just copy-paste or use excel with simple formulas. If you expect this is a repeatable action - create a procedure that will build (and optionally execute) dynamic sql to dml data between tables with same structure. – Anton Krouglov Aug 25 '16 at 20:09