Delete multiple records from a Table

User150433
Tera Guru

Is there a direct function to clean up entire table from script. Something simillar to Truncate table in Oracle.

also what is the difference between deleteRecord and deleteMultiple?? Which one is faster and efficient.

-Amit

7 REPLIES 7

andyliu
ServiceNow Employee
ServiceNow Employee

While it is dangerous, there is a direct function to delete all records from a table:


gs.truncateTable('TABLE_NAME');


PLEASE DO NOT USE THIS FUNCTION!



This is an UNDOCUMENTED feature and should NOT be used under any circumstances.



I can not emphasise how DANGEROUS using something like this can be.



You can seriously damage the structure of your ServiceNow Database by using a command like that, and the only way we'll get you back up and running again, is to restore the whole instance back from backup!



Do you really want to face an instance outage from using one very DANGEROUS command?



If any record elsewhere in the database, references any record in the table that you are truncating, you will potentially "break" your instance!



Due to the way that ServiceNow relate tables (especially in the CMDB/Asset Tables), when using the recommended methods, we carry out a cascade delete, to remove records correctly.



Using any other method is likely to leave orphan ("ghost") records in the database, or potentially cause an outage!



Please use ONLY the supported instructions:



http://wiki.servicenow.com/index.php?title=Deleting_a_Table


http://wiki.servicenow.com/index.php?title=Deleting_All_Records_from_a_Table



Another method which is very safe, it to use a Table Cleaner - which can be scheduled to chug away in the background out of hours, and can remove data based on a a filter i.e. Delete all records created before a set date/time in the required table.



If you have any concerns about removing data, please always contact ServiceNow Technical Support, who will advise you on the best methods to use.



Regards,


Tony Alldis


I agree with Tony on the above.