123

I want to edit some row values once I get a query output in the result grid. Its true that we can right click the table and say open table to get an editable table output, but what I want is editable query output, only certain rows matching for my criteria, and edit them in the result grid.

Can this possible inside Microsoft SQL server Management Studio Express?

3
  • 1
    Mark as duplicate with stackoverflow.com/questions/1535469/…? It also has a fully working solution
    – Brad
    Jan 18, 2013 at 23:18
  • 3
    @Brad - The answer to the question linked to only works if you are using a single table, i.e. no joins. Once you start joining 2 or 3 tables, you can no longer do this. It would be interesting if there were any other solutions. Feb 28, 2013 at 16:04
  • 2
    Read @Yves A Martin answer below for an alternative to editing tables that are JOINED. May 8, 2015 at 19:03

15 Answers 15

112

Yes, This is possible. Right click on the table and Click on Edit Top 200 Rows as show in image below

enter image description here

Then click anywhere inside the result grid, to enable SQL Icon "Show Sql Pane". This will open sql editor for the table you opted to edit, here you can write your own sql query and then you can directly edit the result set of the query.

enter image description here

1
  • 3
    I had to right-click the query and choose "Execute SQL" to take effect in the grid
    – ESP32
    Aug 23, 2023 at 9:22
94

You can do something similar to what you want. Right click on a table and select "edit top 200 rows" (if you are on SQL Server 2008) or "open table" in SQL Server 2005. Once you get there, there is a button on the top that says "SQL"; when you click on it, it lets you write an SQL statement and you can edit the results of it if you click a cell you want to change.

1
  • 2
    This is 2019, its latest version is SSMS 2017, still same approach should be used to edit grid cells! such a bad UI Design! Dec 29, 2018 at 6:18
28

The way you can do this is by:

  • turning your select query into a view
  • right click on the view and choose Edit All Rows (you will get a grid of values you can edit - even if the values are from different tables).

You can also add Insert/Update triggers to your view that will allow you to grab the values from your view fields and then use T-SQL to manage updates to multiple tables.

2
  • 1
    +1 - This is the best and easiest way to edit tables that are JOINED. While this is too much work to accomplish this task it is the only way I can find to do it. May 8, 2015 at 19:01
  • 1
    You cannot edit JOINED tables. Only non JOIN SQL statements. All my cells are uneditable, when I have a JOIN. Feb 27, 2020 at 11:29
24

SSMS - Right Click Results of Edit 200 | Option | Pane | SQL - edit the statement.

1
  • 1
    SSMS 2014, skip "Option" step. May 29, 2018 at 16:41
23
+25

The given answers are still valid. No change in SSMS (SQL Server 2016) has been made on that regard.

You can also use the criteria pane, after doing the "Edit Top 200 Rows".

Edit Top 200 context menu

  1. Show criteria pane
  2. Enter some criterion
  3. Edit data directly in the results grid

Open criteria pane

Additionally, the number of rows for those commands can be customized in your SSMS options.

enter image description here

16

No. There is no way you can edit the result grid. The result grid is mainly for displaying purposes of the query you executed.

This for the reason that anybody can execute complex queries. Hopefully for the next release they will include this kind of functionality.

I Hope that answer your question.

2
  • 6
    I don't see why people voted your answer down. Its actually correct. Once you use a join in your query, you cannot edit the results using the methods suggested in any of the answers so far. +1 from me. Feb 28, 2013 at 16:06
  • You can copy the query to an edit grid SQL pane, which is what the other answers allude to. May 29, 2018 at 16:41
14

UPDATE
as you can see correct solution in Learning answer, In SQL server management 2014 you can
1.click on "Edit Top 200 Rows"
and then
2.clicking on "Show SQL Pane (ctrl+3)"
and
3.removing TOP (200) from select query


Refer to Shen Lance answer there is not a way to edit Result of select query. and the other answers is only for normal select and only for 200 records.

7

Just choose "Edit Top 200 rows", press Ctrl + 3 in the edit grid region (or click "Show SQL Pane") and edit the query...

But please note that this will work only for the query that doesn't contain "join"

0
5

Yes you can edit joined results. (at least in SSMS 2008 R2) After you edit any of the result values in the View that uses joins, you'll need to execute the query again to refresh the results.

You also need to make sure SSMS is configured to allow "Edit All Rows" ... to do this in SSMS - Tools | Options | SQL Server Object Explorer | Commands ... expand the Table and View Options ... put a value of 0 in "Value for Edit Top n Rows command" ... can do this for the select also.

Yves A Martin's response is 100% correct!

Rob

4

First of all right click the tale select 'Edit All Rows', select 'Query Designer -> Pane -> SQL ', after that you can edit the query output in the grid.

3

If you need to frequently perform in-cell edits on SQL databases, HeidiSQL works a treat, couldn't be simpler to use, and is free / open source (donations accepted).

Originally written for MySQL, it can now handle SQL Server, and has experimental (as of Aug 2014) PostgreSQL support as well.

3

Right click on any table in your dB of interest or any database in the server using master if there are joins or using multiple dBs. Select "edit top 200 rows". Select the "SQL" button in the task bar. Copy and paste your code over the existing code and run again. Now you can edit your query's result set. Sherry ;-)

2
  • That Helped A Lit.
    – Asad Ali
    Mar 6, 2017 at 6:33
  • I really hoped this would work for me, but my query contained a where clause and that resulted in 0 results in this view. In a standard view, it returns the entries. Nov 26, 2020 at 3:44
2

If the query is written as a view, you can edit the view and update values. Updating values is not possible for all views. It is possible only for specific views. See Modifying Data Through View MSDN Link for more information. You can create view for the query and edit the 200 rows as given below:

enter image description here

1
  • Why there is negative vote here. The question is not specific to a table editing. The question is about, how can we edit the resultset grid for whatever query output, he is getting. I suggested, if possible, he can create view for the query and edit the rows. Sep 19, 2016 at 20:56
0
  1. To be clear: The option "Value for Edit Top Rows command" has nothing to do with the fact if a result set is editable or not. It is just a way to limit the result set.

  2. Editing the result set of a query based on one and only one table is obviously always possible.

  3. The result set of a query based on more than one table is under following condition possible: You can edit the fields in the result set at once if they belong to one and only one based table in the query! If the fields are Primary Key, then you have to fulfill refresh/"Execute SQL" (Ctrl+R) after each row update, in order to be able to edit a row next time. If the fields are not Primary Key, then you do not need to fulfill refresh/"Execute SQL" (Ctrl+R).

I have tested it on SQL Server 2008 - 2016!

0

Another tip is that the "Esc" key will cancel the record edit being made, in case you need to cancel the change. There doesn't seem to be a button or menu option for this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.