更新视图时出错 [英] Error while Updating view

查看:98
本文介绍了更新视图时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我是新手。我正在使用Views。我创建了一个视图。但是,当我尝试更新它时收到错误消息。



Hi,

I''m a newbie. I''m working out with Views. I have created a view. However, I get an error message when I try to update it.

CREATE VIEW vw_demo
AS
SELECT o.OrderID, o.CustomerID, o.Shipcountry,d.Unitprice, d.quantity
FROM Orders o INNER JOIN [Order Details] d
ON (o.OrderID = d.OrderID AND o.ShipCountry = 'France')





更新视图



Updating view

update vw_demo
SET CustomerID = 'Averroes'
WHERE OrderID =10248





我收到以下错误消息。

消息8152,Level 16,State 4,Line 1

字符串或二进制数据将被截断。

该语句已被终止。




我哪里错了?请帮忙!



提前致谢!



I get the following error message.
Msg 8152, Level 16, State 4, Line 1
String or binary data would be truncated.
The statement has been terminated.


Where am I going wrong? Please help!

Thanks in advance!

推荐答案

1。增加Orders表的CustomerID列的列长度。目前柱长小于8.我希望它能达到8或更高。



2.另一个问题是,为了进行更新查看,请记住以下选项:



SELECT语句只能引用一个数据库表。

SELECT语句不能使用GROUP BY或HAVING子句。

SELECT语句不能在列中使用DISTINCT SELECT子句的列表。

SELECT语句不能引用只读视图。

SELECT语句不能包含任何表达式(聚合,函数,计算列......



以上几点取自以下链接:

http://www.mysqltutorial.org/create-sql-updatable-views.aspx [ ^ ]
1. Increase the column length of CustomerID column of "Orders" table. Currently the column length is less than 8. Make it 8 or above it will work, I hope.

2.Another issue, to make an update able view, keep the following options in mind:

The SELECT statement must only refer to one database table.
The SELECT statement must not use GROUP BY or HAVING clause.
The SELECT statement must not use DISTINCT in the column list of the SELECT clause.
The SELECT statement must not refer to read-only views.
The SELECT statement must not contain any expression (aggregates, functions, computed columns…

The above points taken from the link below:
http://www.mysqltutorial.org/create-sql-updatable-views.aspx[^]


您无法在视图上执行删除/更新或插入。

视图仅提供静态表示数据。



要执行更新,请在存储过程中编写update子句。
You cannot perform delete / update or inserts on a view.
A view provides only a static representation of data.

To perform updates, write update clauses in a stored procedure.


这篇关于更新视图时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆