KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Understanding Get last table number
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: February 11, 2009

In 4D v11 SQL the command Count tables was renamed to Get last table number. More importantly, this command no longer returns the number of tables in the database but, rather, the last table number used. The goal of this Tech Tip is to explain the reason for the rename (rather than the usage of the command).

In fact, in previous versions of 4D the Count tables command does not do what its name implies at all; it does not count the tables in the database. This command returns the value from an internal counter. In this way it behaves much like Sequence number. Sequence number does not count the records in a table but, rather, increments an internal counter every time a record is saved. Similarly, each time a table is created in the database the value returned by Count tables is incremented. Since tables cannot be deleted in previous versions of 4D, the design of Count tables is valid and returns the right value.

This command is unchanged in 4D v11 SQL other than in name. That is, the behavior is *exactly* the same. The command still returns the value in the internal counter. However, now that tables can be deleted, the result is that it no longer reflects the number of tables in the database, so the command was renamed. Interestingly the new name is perhaps more accurate than the old name!

Commented by Luis Pineiros on February 27, 2009 at 5:20 PM
A good idea when using the Get last table number command is to use the Is table number valid command as well. It checks whether a table has been deleted, therefore creating gaps in the sequence of tables.