Score:1

SQL Server Management Studio 2019 save to CSV and then import it after test

in flag

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

uz flag
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.
Mighty avatar
in flag
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
Score:1
cn flag

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.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.