2014-01-18 68 views
0

我遇到问题。我研究过但我没有得到解决方案。MySQL:无法在MySQL视图中插入

我想在MySQL视图插入,但我得到以下错误:

Can not modify more than one base table through a join view 'my_view' 

查询:

INSERT INTO `aosship`.`products_inventory` (

`products_id` , 
`inventory_id` , 
`parent_id` , 
`qty_on_stock` , 
`inventory_date` , 
`expiration_date` , 
`supplier_id` , 
`qty_in_back_order` , 
`location_id` , 
`product_id` , 
`tax` , 
`qty` , 
`upc` , 
`product_name` , 
`description` , 
`ebt` , 
`wic` , 
`discontinued` , 
`reorder_point` , 
`reorder_qty` , 
`taxable` , 
`time_stamp` , 
`product_control` , 
`price` , 
`catagory_name` , 
`temp_product` , 
`cost` 
) 
VALUES (
'00000000000', '0', '1', '1', '2014-01-18 00:00:00', '2014-01-18', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '2014-01-18 00:00:00', '1', '1', '1', '1', '1' 
)

查询创建视图:

CREATE 
    ALGORITHM = UNDEFINED 
    DEFINER = `root`@`localhost` 
    SQL SECURITY DEFINER 
VIEW `aosship`.`products_inventory` AS 
    select 
     `aosship`.`products`.`ID` AS `products_id`, 
     `aosship`.`inventory`.`ID` AS `inventory_id`, 
     `aosship`.`inventory`.`parent_id` AS `parent_id`, 
     `aosship`.`inventory`.`qty_on_stock` AS `qty_on_stock`, 
     `aosship`.`inventory`.`inventory_date` AS `inventory_date`, 
     `aosship`.`inventory`.`expiration_date` AS `expiration_date`, 
     `aosship`.`inventory`.`supplier_id` AS `supplier_id`, 
     `aosship`.`inventory`.`qty_in_back_order` AS `qty_in_back_order`, 
     `aosship`.`inventory`.`location_id` AS `location_id`, 
     `aosship`.`inventory`.`product_id` AS `product_id`, 
     `aosship`.`inventory`.`tax` AS `tax`, 
     `aosship`.`inventory`.`qty` AS `qty`, 
     `aosship`.`products`.`upc` AS `upc`, 
     `aosship`.`products`.`product_name` AS `product_name`, 
     `aosship`.`products`.`description` AS `description`, 
     `aosship`.`products`.`ebt` AS `ebt`, 
     `aosship`.`products`.`wic` AS `wic`, 
     `aosship`.`products`.`discontinued` AS `discontinued`, 
     `aosship`.`products`.`reorder_point` AS `reorder_point`, 
     `aosship`.`products`.`reorder_qty` AS `reorder_qty`, 
     `aosship`.`products`.`taxable` AS `taxable`, 
     `aosship`.`products`.`time_stamp` AS `time_stamp`, 
     `aosship`.`products`.`product_control` AS `product_control`, 
     `aosship`.`inventory`.`price` AS `price`, 
     `aosship`.`inventory`.`catagory_name` AS `catagory_name`, 
     `aosship`.`products`.`temp_product` AS `temp_product`, 
     `aosship`.`products`.`cost` AS `cost` 
    from 
     (`aosship`.`inventory` 
     join `aosship`.`products` ON ((`aosship`.`inventory`.`product_id` = `aosship`.`products`.`ID`)))

请指导我该如何解决这个问题。

非常感谢。

+0

你应用了什么查询? –

+0

我编辑并添加了查询,所以请看看。 – Maria

回答

1

使用VIEW,您一次只能更新一个表格。

如果您想用一个查询更新多个表,您可以查看存储过程

+0

但请检查我的问题上面的查询。它只是插入一张桌子。我没有更新多个表。 – Maria

0

如果您使用连接创建视图,并且创建的视图包含视图表 中的所有列,则可以使用两个插入语句插入视图表。

+0

但我没有使用两个插入语句。我只使用单个语句来插入。 – Maria

+0

你可以提交你的查询创建视图吗? –

+0

我已经在我的问题中插入了我的查询,所以请检查一下。 – Maria