Adding data to the end of a table

In a relational database, the rows of a table are not ordered, and thus, the table has no end. However, depending on your goal, you can perform several actions to simulate adding data to the end of a table.

About this task

Question: How can I add data to the end of a table?

Answer: Though the question is often asked, it has no meaning in a relational database. The rows of a base table are not ordered; hence, the table does not have an end.

However, depending on your goal, you can perform one of the following actions to simulate adding data to the end of a table:
  • If your goal is to get a result table that is ordered according to when the rows were inserted, define a unique index on a TIMESTAMP column in the table definition. Then, when you retrieve data from the table, use an ORDER BY clause that names that column. The newest insert appears last.
  • If your goal is for Db2 to insert rows in the next available free space, without preserving clustering order, specify the APPEND YES option when you create or alter the table. Specifying this option might reduce the time it takes to insert rows, because Db2 does not spend time searching for free space.