How can I generically detect if a database is 'empty' from Java?

There are some cross-database SQL-92 schema query standards - mileage for this of course varies according to vendor SELECT COUNT(*) FROM INFORMATION_SCHEMA. TABLES WHERE TABLE_TYPE = Aspx More specifically in SQL Server, sysobjects metadata predates the SQL92 standards initiative SELECT COUNT(*) FROM sysobjects WHERE type = 'U Query above returns the count of User tables in the database. More information about the sysobjects table here: http://msdn.microsoft.com/en-us/library/aa260447 (SQL.80).aspx.

There are some cross-database SQL-92 schema query standards - mileage for this of course varies according to vendor SELECT COUNT(*) FROM INFORMATION_SCHEMA. TABLES WHERE TABLE_TYPE = Support for these varies by vendor, as does the content of the columns for the Tables view. SQL implementation of Information Schema docs found here: msdn.microsoft.com/en-us/library/aa93320...).aspx More specifically in SQL Server, sysobjects metadata predates the SQL92 standards initiative.

SELECT COUNT(*) FROM sysobjects WHERE type = 'U' Query above returns the count of User tables in the database. More information about the sysobjects table here: http://msdn.microsoft.com/en-us/library/aa260447(SQL.80).aspx.

I don't know if this is a complete solution ... but you can determine if a table is a system table by reading the table_type column of the ResultSet returned by getTables: int nonSystemTableCount = 0; tables = metadata. GetTables(null, null, null, null); while( tables. Next () ) { if(!"SYSTEM TABLE".

Equals( tables. GetString( "table_type" ) ) ) { nonSystemTableCount++; } } boolean isEmpty = nonSystemTableCount == 0; return isEmpty; In practice ... I think you might have to work pretty hard to get a really reliable, truly generic solution.

If so you might be able to simply select from a subset of tables that you are familiar with to look for data. You also might need to be concerned about static data perhaps added to a lookup table that looks like 'data' from a cursory glance, but might in fact not really be 'data' in an interesting sense of the term. Can you provide any more information about the specific problem you are trying to tackle?

I wonder if with more data a simpler and more reliable answer might be provided. Are you creating these databases? Are you creating them with roughly the same constructor each time?

What kind of process leaves these guys hanging around, and can that constructor destruct? There is certainly a meta data process to loop through tables, just through something a little more custom might exist.

Basically, I want to be sure a database is empty before I start running a setup process on it (to protect users from accidentally targeting a database which already contains other data by mistake). A simpler solution might be possible, but I can build that up myself if there's no good generic one. – Matt Sheppard Sep 23 '08 at 4:16.

In Oracle, at least, you can select from USER_TABLES to exclude any system tables.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions