How to edit data in result grid in SQL Server Management Studio

后端 未结 14 2253
广开言路
广开言路 2020-12-23 14:32

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, b

相关标签:
14条回答
  • 2020-12-23 14:52

    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".

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

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

    0 讨论(0)
  • 2020-12-23 14:53

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

    0 讨论(0)
  • 2020-12-23 14:53

    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 讨论(0)
  • 2020-12-23 14:54
    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 讨论(0)
  • 2020-12-23 14:58

    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

    0 讨论(0)
  • 2020-12-23 14:59

    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.

    0 讨论(0)
提交回复
热议问题