2014-01-18 64 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