Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

List all tables in my instance that contain data

Saurav
Tera Expert

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

3 REPLIES 3

Mark Manders
Mega Patron

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 Roethof
Tera Patron
Tera Patron

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

LinkedIn

Thanks Mark Roethof .. this was exactly what I was looking for..