Quantcast
Channel: SCN: Message List - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 8968

Re: Identifying foreign key constraint violation errors

$
0
0

For your case you must use the EXIT HANDLER statement, you can find more information in http://help.sap.com/hana/SAP_HANA_SQL_Script_Reference_en.pdf

 

To find the listing of SQL_ERROR_CODE, see the following document:

http://help.sap.com/hana/SAP_HANA_SQL_and_System_Views_Reference_en.pdf

 

 

Then I put an example of use of the judgment EXIT HANDLER with error 'Foreing Key violation'.

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

DROP TABLE "CUSTOMER"; 

CREATE COLUMN TABLE "CUSTOMER" ( 

          CUSTID          INT, 

          NAME          VARCHAR(60), 

          ADDRESS          VARCHAR(60), 

          PRIMARY KEY (CUSTID) 

          );  

DROP TABLE "ORDER"; 

CREATE COLUMN TABLE "ORDER" ( 

          ORDID          INT, 

          CUSTID          INT, 

          ORDDATE          DATE, 

          NETVAL          DECIMAL(23,2), 

          PRIMARY          KEY (ORDID), 

          FOREIGN KEY (CUSTID) REFERENCES "CUSTOMER" 

          ); 

                  

DROP PROCEDURE TEST_INSERT_ORDER;

CREATE PROCEDURE TEST_INSERT_ORDER(ORDID INT) AS

BEGIN

 

 

DECLARE EXIT HANDLER FOR SQL_ERROR_CODE 461

BEGIN

--In your case you have validate what foreingkey constaint is produce the error.

SELECT 'Value of CUSTID not exist!', ::SQL_ERROR_CODE, ::SQL_ERROR_MESSAGE FROM DUMMY;

END;

 

 

INSERT INTO "ORDER" (ORDID,CUSTID,ORDDATE,NETVAL) VALUES (:ORDID,1,NOW(),10.5);

 

 

END;

 

 

CALL TEST_INSERT_ORDER(1)

 

-------------------------------------------------------------------------------------------------------------------------------------------------------

 

Regards.


Viewing all articles
Browse latest Browse all 8968

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>