如何在 SQL Server Management Studio 中编辑结果网格中的数据

发布于 2024-10-09 13:04:49 字数 165 浏览 3 评论 0原文

在结果网格中获得查询输出后,我想编辑一些行值。 确实,我们可以右键单击表并说打开表来获取可编辑的表输出,但我想要的是可编辑的查询输出,只有某些行符合我的条件,然后在结果网格中编辑它们。

这可以在 Microsoft SQL Server Management Studio Express 中实现吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

凉城凉梦凉人心 2024-10-16 13:04:49

是的,这是可能的。右键单击表格,然后单击编辑前 200 行,如下图所示

在此处输入图像描述

然后单击结果网格内的任意位置,以启用 SQL 图标“显示 Sql 窗格”。这将为您选择编辑的表打开sql编辑器,在这里您可以编写自己的sql查询,然后您可以直接编辑查询的结果集。

在此处输入图像描述

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

挽心 2024-10-16 13:04:49

您可以做一些与您想要的类似的事情。右键单击表并选择“编辑前 200 行”(如果您使用的是 SQL Server 2008)或 SQL Server 2005 中的“打开表”。到达那里后,顶部有一个按钮显示“SQL”;当你点击它时,它可以让你编写一条 SQL 语句,如果你点击你想要更改的单元格,你可以编辑它的结果。

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.

皓月长歌 2024-10-16 13:04:49

您可以执行此操作的方法是:

  • 将选择查询转换为视图,
  • 右键单击视图并选择编辑所有行(您将获得可以编辑的值网格 - 即使这些值是来自不同的表)。

您还可以将插入/更新触发器添加到视图中,这将允许您从视图字段中获取值,然后使用 T-SQL 管理对多个表的更新。

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.

疯狂的代价 2024-10-16 13:04:49

SSMS - 编辑 200 的右键单击结果 |选项 |窗格| SQL - 编辑语句。

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

财迷小姐 2024-10-16 13:04:49

给出的答案仍然有效。 SSMS(SQL Server 2016)在这方面没有做出任何改变。

执行“编辑前 200 行”后,您还可以使用条件窗格。

编辑前 200 名上下文菜单

  1. 显示条件窗格
  2. 输入一些条件
  3. 直接在结果网格中编辑数据

打开条件窗格

此外,可以在 SSMS 选项中自定义这些命令的行数。

输入图片描述这里

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

锦欢 2024-10-16 13:04:49

不可以。您无法编辑结果网格。结果网格主要用于显示您执行的查询的目的。

这是因为任何人都可以执行复杂的查询。希望下一个版本将包含此类功能。

我希望能回答你的问题。

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.

雨落□心尘 2024-10-16 13:04:49

更新
正如您可以在学习答案中看到正确的解决方案,
在 SQL Server Management 2014 中,您可以
1.点击“编辑前 200 行
然后
2.单击“显示 SQL 窗格 (ctrl+3)

3.从选择查询中删除TOP (200)


请参阅Shen Lance的回答,没有办法编辑选择查询的结果。其他答案仅适用于正常选择且仅适用于 200 条记录。

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.

巡山小妖精 2024-10-16 13:04:49

只需选择“编辑前 200 行”,在编辑网格区域中按 Ctrl + 3(或单击“显示 SQL 窗格”)并编辑查询...

但请注意,这仅适用于不包含的查询“加入”

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"

何必那么矫情 2024-10-16 13:04:49

是的,您可以编辑连接结果。 (至少在 SSMS 2008 R2 中)在使用联接的视图中编辑任何结果值后,您需要再次执行查询以刷新结果。

您还需要确保 SSMS 配置为允许“编辑所有行”...在 SSMS - 工具 | 中执行此操作选项| SQL Server 对象资源管理器 |命令...展开表和视图选项...在“编辑前 n 行命令的值”中输入值 0...也可以对选择执行此操作。

Yves A Martin 的回答 100% 正确!

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

作死小能手 2024-10-16 13:04:49

首先右键单击故事选择“编辑所有行”,选择“查询设计器 ->”窗格 -> SQL ',之后您可以在网格中编辑查询输出。

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.

岁吢 2024-10-16 13:04:49

如果您需要频繁地对 SQL 数据库执行单元内编辑,HeidiSQL 可以满足您的需要。治疗,使用起来再简单不过了,并且是免费/开源的(接受捐赠)。

它最初是为 MySQL 编写的,现在可以处理 SQL Server,并且还具有实验性(截至 2014 年 8 月)PostgreSQL 支持。

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.

枫以 2024-10-16 13:04:49

如果存在联接或使用多个 dB,则右键单击您感兴趣的 dB 中的任何表或使用 master 的服务器中的任何数据库。选择“编辑前 200 行”。选择任务栏中的“SQL”按钮。将代码复制并粘贴到现有代码上,然后再次运行。现在您可以编辑查询的结果集。雪利酒;-)

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 ;-)

似梦非梦 2024-10-16 13:04:49

如果查询被编写为视图,您可以编辑视图并更新值。不可能为所有视图更新值。仅适用于特定视图。有关详细信息,请参阅通过查看 MSDN 链接修改数据。您可以为查询创建视图并编辑 200 行,如下所示:

在此处输入图像描述

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

迟月 2024-10-16 13:04:49
  1. 需要明确的是:“编辑顶行命令的值”选项与结果集是否可编辑无关。这只是限制结果集的一种方法。

  2. 基于一张且仅一张表编辑查询的结果集显然总是可能的。

  3. 基于多个表的查询的结果集可能存在以下情况:
    如果结果集中的字段属于查询中的一个且仅一个基于表,您可以立即编辑它们!如果字段是主键,那么您必须在每次更新行后执行刷新/“执行SQL”(Ctrl+R),以便下次能够编辑行。如果字段不是主键,则不需要执行刷新/“执行SQL”(Ctrl+R)。

我已经在 SQL Server 2008 - 2016 上测试过它!

  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!

白昼 2024-10-16 13:04:49

另一个提示是,“Esc”键将取消正在进行的记录编辑,以防您需要取消更改。似乎没有为此的按钮或菜单选项。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文