Edit selected rows manually in SQL Server

2020-05-22 00:04发布

问题:

I have a database in which some editing operations have to be done manually on some rows. I have the SQL Server Management Studio Express. In SSMS, to edit the rows, normally the option is:

Select DB > Table > Right Click > Edit top 200 rows

But, the problem here is that I only have to edit some selected rows. I am able to retrieve these selected rows by the following query:

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT *
  FROM [test].[dbo].[Sheet1] WHERE Item1 IS NULL OR Item2 IS NULL

Now, I have to perform some edit operations (moving some data from some columns to others) which can't be performed with a query because of no single observable pattern for editting. So, the question remains, how can I get these rows in edit mode to do my task?

回答1:

Click edit rows on the table and then open the sql tab of that query and add your predicate there. And that's how you can edit filtered records.



回答2:

As you said, go for

Select DB > Table > Right Click > Edit top 200 rows

Now the window opens with the top 200 query and the results editable.

Now change the query to the one with your where clause and hit F5



回答3:

After you have your 200 rows displayed for editing, you can also click on the "SQL" icon which will now be available above the Object Explorer. This is another way to have the SQL displayed which you can now edit as needed in order to change the desired rows.