Click here to Skip to main content
15,902,777 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
Posted

1 solution

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:
SQL
Create View MyView As
SELECT * Customers WHERE Age > 18
/*Can update*/

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

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]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900