List all tables in my instance that contain data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 02:17 PM
I would like to see a script which outputs all the tables on my platform which contains a data (list).
I am not able to get a script which pulls all tables on my instance that contain a data
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 11:05 PM
Not sure what use it will have to see this information but you can try this:
var grTable = new GlideRecord('sys_db_object');
grTable.addQuery('super_class', ''); // Ensure you're only getting the base tables
grTable.query();
gs.print('Tables with data:');
while (grTable.next()) {
var tableName = grTable.getValue('name');
var grData = new GlideRecord(tableName);
grData.setLimit(1); // Only need to check if there is at least one record
if (grData.query() && grData.hasNext()) {
gs.print(tableName);
}
}
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-22-2024 11:57 PM - edited ‎08-22-2024 11:58 PM
Hi there,
Have a look at table:
sys_physical_table_stats
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-24-2024 11:06 PM
Thanks Mark Roethof .. this was exactly what I was looking for..