Expand my Community achievements bar.

SOLVED

How to Truncate a table?

Avatar

Level 2

Hi everyone

 

I am trying to truncate the contents of a custom table in the Adobe Campaign database. I created that table to hold a set of data that is imported on a daily basis from an external file,but I need to truncate it before loading the data set.

 

I know I could use the Update activity to delete records, but that requires an input. I could build that input by querying all data in the target table first and pass it to the Update activity, then the Update activity would delete the records from the incoming population. However, it would be much more efficient to just truncate the full table.

 

Can someone provide guidance on how to do it?

 

Cheers

Hugo

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @hugol_vallejo

To truncate the table please use SQL Code activity under Actions tab and use command:

TRUNCATE TABLE <tableName>

Regards,

Milan

View solution in original post

7 Replies

Avatar

Correct answer by
Community Advisor

Hi @hugol_vallejo

To truncate the table please use SQL Code activity under Actions tab and use command:

TRUNCATE TABLE <tableName>

Regards,

Milan

Avatar

Level 2

Thanks Milan

Never had used the SQL activity, so that was an easy one. Thanks for the quick reply

Avatar

Level 1

Hi,Milan_Vucetic can u tell me the code to truncate schema in sql

 

 

Avatar

Community Advisor

Hi @Rishave,

 

just be carefull here.

Since the intention is to drop all the objects for a schema, why not just drop and recreate that schema with all the required privileges (rather than dropping each and every objects.

drop user <user_name> CASCADE;
then re-create that schema again.

 

if you want to keep the schema but to delete all objects you may try this:

select 'drop '||object_type||' '|| object_name || ';' from user_objects where object_type in ('VIEW','PACKAGE','SEQUENCE', 'PROCEDURE', 'FUNCTION', 'INDEX'); 

Please, ensure you are logged into a proper schema.

Cheers,
Milan

Avatar

Level 2

Hi Milan,

Thank you for the solution. This worked.

Avatar

Level 2

Hi Milan,

 

I am currently facing an issue while attempting to truncate a table in Campaign V8. Despite trying various approaches such as using the table label, internal name, and the name provided in the documentation tab of the data schema, I consistently encounter an error indicating that the table does not exist. Interestingly, in my previous project, the same command worked flawlessly in Campaign V7.Whether there have been any changes to the command syntax or functionality in Campaign V8 that could be causing this issue. 

Need your guidance and assistance on this and looking forward to your prompt response.

 

 

Regards,

Ankita

Avatar

Community Advisor

Hi @AnkitaV3131 

Adobe v7 (if we talk about on-premise solution) you had previously could be on different database. Adobe v8 natively should work with PostgreSQL as primary base and Snowflake as secondary base. If your data model is not extended and if you not storing data on Snowflake I would suggest that you explore syntax for PostgreSQL. 
Could it be that you already dropped the table but just schema remained?