2016-05-04 33 views
1

我需要解決方案來解決我的問題。提前致謝。我使用Derby DB。更新後觸發,錯誤:標量子查詢只允許返回一行

我有一個只有幾列的表。我更新後爲我需要的特定列創建了觸發器。當我嘗試更新行中的列時,出現此錯誤。

Error code 30000, SQL state 21000: Scalar subquery is only allowed to return a single row.

只有在主表中有兩行或多行時纔會出現此錯誤。如果我在表「帳戶」中只有一行,一切正常。

這是觸發代碼:(賬戶是主桌,accounts_history新表)

CREATE TRIGGER aft_update AFTER UPDATE of balance,date 
      ON accounts 

FOR EACH ROW MODE DB2SQL 

insert into accounts_history 

(old_id,new_name,new_balance,new_date) values 
      (

(select id from accounts),(select name from accounts), 

(select balance from accounts),(select date from accounts) 
      ); 
+0

謝謝老兄!它工作正常:D –

回答

1

標量子查詢應該返回最多一行和一列。

只需使用insert . . . select

insert into accounts_history(old_id, new_name, new_balance, new_date) 
    select id, name, balance, date 
    from accounts; 
相關問題