Delete multiple records from a Table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2009 02:28 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2009 07:44 AM
The simplest method is in the Tables and Columns module. Select the table and click the Delete All Records button.
This actually runs the deleteAllRecords business rule which performs a deleteRecord call on each record.
The deleteMultiple method does have some shortcuts built in to make it faster on certain tables, otherwise it does the same thing as deleteRecord. It can only streamline deletes for tables without auditing, delete biz rules, and no external references.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-07-2015 09:17 PM
A quicker way to do this would be use a direct SQL command to truncate the entire data, it will be done really fast and no record will be left behind in that table. Run the following command in the Scripts - Background:
gs.sql("truncate table <table_name>");
Hope this helps
Regards,
Sanjeev Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2015 02:52 AM
Sanjeev,
This is an UNDOCUMENTED feature and should NOT be used under any circumstances.
Truncating tables is an extremely DANGEROUS process.
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, 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
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-10-2015 03:09 AM
Best way to delete all records from table is to navigate to Tables and Columns> Find you table and click on delete All records. This might take time but that is the best way I think.
If you want to delete a records via script, create a schedule job and put your code inside that. This will not impact system performance too much.
I hope this helps.
Thanks,
Ashish rai