Tsql help - doing a large update from CSV file to a table in ssms I have been given a csv file with just ids in there and those ids are in a table in ssms with columns that require updating. Out of 90,000 ids in that table, only 83,000 of them require updating from the csv file.
the main table is:
ID  ENABLED    AGREED
1       1                       no  
2       1                       no
3       1                       no
4       0                       yes

I know I can do an update on the table from the ids i have been given in the csv such as:
update table1
set enabled = 0,
agreed = 'yes',
where id in('1','2','3')

however, my problem is, there are 83,000 of them that require updating to those specific conditions and wanted to find the best way to do this. I have been told to write a script to import the CSV into a temp table, then join that temp table onto the main table and perform the update rather than hard code a list of id's in a script.
How can I do this? Does anyone know a better way?
You can use the Import Flat File feature in SSMS to import a CSV file to a Table in your database. (Import Data is another feature you can use too but it's a little more bulky and older.) Either of these features can be found be right clicking on the database you want to import into, clicking Tasks, then clicking Import Flat File (or Import Data if you prefer). Then it's just a matter of following the Import Wizard which is only a few steps.
If the update you're making to your main table are the same values for all 83,000 rows that are being updated, then you can just update them with a similar hard-coded update query to this, after you import your CSV file:
UPDATE M
SET M.enabled = 0, -- Hard-coded value for all rows
    M.agreed = 'yes' -- Hard-coded value for all rows
FROM MainTable AS M
INNER JOIN CsvImportedTable AS C
    ON M.id = C.id

Otherwise if you have different values you need to set for different rows within your list of 83,000 IDs then you'll need to pre-define those values in new columns in the CSV file first (using Excel for example) before you import it. Then after you import it, your CSV table will have those columns as well so you can do a more dynamic update like this:
UPDATE M
SET M.enabled = C.enabledNewValue, -- Values you entered in your CSV
    M.agreed = C.agreedNewValue -- Values you entered in your CSV
FROM MainTable AS M
INNER JOIN CsvImportedTable AS C
    ON M.id = C.id


Additional resources on importing CSVs and data into a database via SSMS:

SQLShack - Importing and Working with CSV Files in SQL Server

Microsoft Books Online on the Import Data feature

MSSQLTips - Simple way to import data into SQL Server