如何在View中编写更新,插入,删除 [英] how to write update,insert,delete in View

查看:85
本文介绍了如何在View中编写更新,插入,删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建View MyView为
更新客户设置Customers.MTDSale = 0,Customers.YTDSale = 0,Customers.LastMonthSale = 0,Customers.LastYearSale = 0,Customers.LastYearThisMonthSale = 0,Customers.LastYearLastMonthSale = 0,Customers.ChannelID = 0;

Create View MyView As
UPDATE Customers SET Customers.MTDSale = 0, Customers.YTDSale = 0, Customers.LastMonthSale = 0, Customers.LastYearSale = 0, Customers.LastYearThisMonthSale = 0, Customers.LastYearLastMonthSale = 0, Customers.ChannelID = 0;

推荐答案

您不能将视图创建为选择.

如果视图<代码lang ="sql">选择包含一个表:
You can''t create a view as an Update, you need to create the view as a Select.

You can only perform the Update, Delete and Insert if the view Select contains one table:
Create View MyView As
SELECT * Customers WHERE Age > 18
/*Can update*/


Create View MyView As
SELECT * Customers, CustomerAddress WHERE Age > 18
and 
customer.Id = CustomerAddress.Id
/*Cannot update*/


此外,您只能执行在视图中指定足够的列以满足任何非null约束的插入操作.

作为附带说明,您似乎正在尝试设置问题的默认值,这真的是您想要的吗?

[正确的代码格式]


Additionally, you can only perform an insert where enough columns in the view are specified to satisfy any not null constraints.

As a side note, it looks like you are trying to set default values in your question, is this really what you want instead?

[Corrected code formatting]


这篇关于如何在View中编写更新,插入,删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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