MySQL Forums
Forum List  »  General

Re: Insert Into Inside an IF statement
Posted by: Peter Brawley
Date: November 09, 2017 02:59PM

> IF ( ACCOUNT.CASH_BALANCE >= (TCOUNT * TBUYPRICE),

IF ... THEN and no comma. Read the documentation about IF...END IF in the manual page on stored procedure syntax.

> INSERT INTO TRADES (TRADE_ID, ACCOUNT_ID, TRADE_NAME, TRADE_COUNT, TRADE_BUYDATE, TRADE_BUYPRICE)
> VALUES (TID, ID, T_NAME, TCOUNT, TBUYDATE, TBUYPRICE)

If any of these variables has the same name as a column of a referenced column, MySQL will be unable to determine which is being referred to. Adopt a naming rule for variables such that it cannot refer to any column of any table, and stick to the rule.

> AND UPDATE ACCOUNT.CASH_BALANCE

We can't make up syntax. Nowhere does the documentation say that commands can be ANDed in this way. Insert and Update are separate commands.

Using upper case for database object names like tables and columns will create problems if the database ever port to Linux, and introduces readability issues. Best practice is to stick to lower case.



Edited 1 time(s). Last edit at 11/09/2017 03:48PM by Peter Brawley.

Options: ReplyQuote


Subject
Written By
Posted
Re: Insert Into Inside an IF statement
November 09, 2017 02:59PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.