Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I am looking for a way to drop all existing tables in my datamodel, except some Tables which can be stated in the script.
I have found in the Community two solutions, which I tried and it definitely does not work for me.
Anybody has a workable solution for this case?
Thx a lot,
Chris
I Christian,
What is your issue with drop table statement?
I had a problem wit it too, but I resolved. My problem was that at the end of the script not all table were dropped.
After tests and retest, I undertood that, during dropping, the 'TableNumber' of existing table change!! So, if for example the number of "TableX" at the beginning is 15, during dropping can change in 10, 5,0...and when the n of your FOR is 15, the function "tablename(15)" is null.
Then I revolved using a different approach...not a cycle, but a long string.
FOR i = 0 to NoOfTables()-1
TableList:
LOAD TableName($(i)) as Tablename AUTOGENERATE 1
WHERE not WildMatch(TableName($(i)), 'TableA','TableB','TableC');
NEXT i
TableList1:
load concat(Tablename, ',') as Tablename1
resident TableList;
let vdrop= peek('Tablename1');
DROP Tables TableList,TableList1;
DROP Tables $(vdrop);
I hope this can help you.
Very nice and useful code, @graziellas82 !
I would like to suggest a little improvement:
Using '['&CONCAT(TABLENAME,'],[')&']' AS TABLENAME1 instead gives support for tables with space on it names.
Regards!