on ‎2012 May 10 12:47 PM
This might sound like a very stupid question, but I have been going through the HANA PDF's and cannot seem to find the answer I am looking for.
I am currently in the process of performing a HANA POC and am trying to create a large SQL script that will create multiple tables and populate those tables with some data.
Being OCD, I like my scripts to run through with zeros errors. The part where I need the help is in the DROP TABLE part of the script.
I have the DROP TABLE lines there, but if a table does not already exists, I get an error message.
Does HANA have the equaivilant of a IF EXISTS ..... DROP TABLE ??
Any help would be greatly appreciated!
Request clarification before answering.
I think you can make use of TABLES and search for existance of the table (column = table_name) to be dropped.
You can write a procedure and also make use of EXISTS (if required).
Regards,
Ravi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think I jumped too early into this.
As you mentioned, you need completely ERROR free code which doesn't throw any exception (which I am not sure how to handle in HANA as of now, like specific "No data Found", "SQL Exception" etc).
To achieve this, I think you might have to write a custom program to delete the table with table_name and schema_name as input parameters and dynamic SQL with "EXEC 'DROP TABLE '||<input_table_name>; type command.
Not sure if I am over complicating this, but worth a try.
Regards,
Ravi
As I said, I AM overcomplicating the things.. but what the heck, I could try something new
=================================
drop procedure pr_drop_table;
CREATE PROCEDURE pr_drop_table (
IN v_in_schema VARCHAR (30), -- Schema Name holding table to be dropped
IN v_in_table VARCHAR (30) -- Table name to be dropped
)
LANGUAGE SQLSCRIPT
AS
v_tab_exists smallint := 0;
BEGIN
-- Create a dummy table
CREATE TABLE t_dummy (v_tname VARCHAR(30));
-- Insert into the dummy table a value from TABLES with table_name as parameter
INSERT INTO t_dummy
SELECT table_name FROM TABLES
WHERE schema_name = :v_in_schema AND table_name = :v_in_table;
-- Check how many records are inserted
-- If table exists, ROWCOUNT will be 1 or else 0
v_tab_exists := ::ROWCOUNT;
IF v_tab_exists > 0 THEN
EXEC 'DROP TABLE '||:v_in_table;
END IF;
-- Delete the dummy table
DROP TABLE t_dummy;
END;
| User | Count |
|---|---|
| 13 | |
| 8 | |
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.