Mass deletion of Records from Computer Table(cmdb_ci_computer)

sharada_janagar
Kilo Explorer

Hi,

 

Could any one please guide me on how to delete all records from cmdb_ci_computer table using Glide Record query?( I have tried using "Delete all Records" By going to Tables and Columns but it is not deleting all records at once.)

 

Thanks and Regards,

Sharada.


1 ACCEPTED SOLUTION

harikrish_v
Mega Guru

HI Sharada,



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



Thanks & Regards,


Hari


View solution in original post

12 REPLIES 12

Paul Terkun - I did try this, but I have one question. I did this for the PVDC class. I cleaned up all the records, plus the orphaned records from the extending tables, but when I click on the PVDC container menu there is something weird - I don' see any records, but the counter still shows the number. How did you fight that?



find_real_file.png


pault1
Kilo Contributor

This is the same behavior I saw when I had cleaned up a child table, but the parent table still contained orphaned records. So my only guess is you missed an extended table somewhere. Work your way down from the PVDC table, looking at the properties of each table to get the table it extends. Run a background scripts query to make sure each extended table has been cleaned up. Good luck!


PLEASE DO NOT EVER TRUNCATE CMDB TABLES!



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!



The use of gs.sql has been deprecated in ServiceNow Releases from Geneva, due to the damage, and instances outages that has been caused by it.



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