1

I'm fairly new to SQL, and I'd like to do some quick testing.

I'm about to update a field in 81 records in a table. After each test, I'd like to get back where I started. I've saved off my query results to a CSV. I haven't been able to find how to import my CSV to update only the original records. I do have an id field, so I the records are unambiguous.

The table I'm applying this to is big enough that a full restore takes a little too long.

I'm sure it's simple, but my searches are mostly finding how to create a new table when importing a CSV.

SQL Server Management Studio 2019

Mighty
  • 111
  • 2
  • 2
    This is not possible using the built-in features of SSMS, and also not a proper way of messing with data. If you're testing, you should be working on a copy of the data. – longneck Aug 15 '23 at 01:15
  • I am working on a copy of the production database. I'm disappointed to learn that there's no way to bring in a subset of the table. I realize there are 10,000 ways importing a CSV can go wrong. But, this seems useful, to me. Albeit, if I screw up my query, there's a good chance it'll spill past the records I exported. So it probably isn't as useful as I hope – Mighty Aug 15 '23 at 01:24

1 Answers1

1

I'm fairly new to SQL,

This is not a SQL question but a tool question. SQL is the language, Management Studio is - as the name says - a management tool you may or may not use.

I'm about to update a field in 81 records in a table. After each test, I'd like to get back where I started.

Backup and Restore words you know? That is the ultimate "redo after test". Using a transaction and rolling back another one. Then there is undoing.

The table I'm applying this to is big enough that a full restore takes a little too long.

So, the database (because restore is not table level) is terabytes? Anyhow...

There are other ways than to do a proper backup. You can always copy that table partially into another buffer table that you create possible in a test namespace.

Create backup table, copy data you want to undo there, after test copy back.

TomTom
  • 51,649
  • 7
  • 54
  • 136