How to generate unique row IDs in Baserow

How to generate unique IDs with Baserow formula

Generating unique serial numbers can be used to identify a specific item or product or for security and authentication purposes. This is particularly important in industries such as manufacturing or retail where there may be many similar items or products.

Getting a unique ID for every row in Baserow can be a useful way to keep track of your data and ensure that each row is easily identifiable. By assigning a unique serial number to each item, it becomes much easier to keep track of inventory, sales, and warranties and prevent unauthorized use or piracy.

What we’ll do

In this tutorial, we will explore how to generate unique serial numbers that can help with inventory management, verification of product authenticity, security, and tracking of the history of items.

We’ll follow these steps:

  • Set up a Baserow database.
  • Use the row_id() function.
  • Generate unique serial numbers with concat function.

What we’ll need

We will integrate no-code tools. These are the tools we need:

How to get the unique row IDs

1. Set up a Baserow database

First, log in to your Baserow account (or create one, if you haven’t already). Storing data in a Baserow database makes it easier for everyone on the team to access and work with it.

Create a workspace by clicking the + Create workspace button in the dashboard. Name the workspace, then click the Add workspace button to save the newly-created workspace.

After you’ve created a workspace, create a new database from scratch, or add a database from the template library. For this tutorial, we will use the Restaurant Management template. Using a database template can save you time by providing a pre-built structure that you can customize to your needs.

It’s easy to get started with a Baserow template. In this tutorial, we will generate employee numbers to be printed on photo ID badges. Click on the Use this template button on the template page and choose a workspace which the template will be installed into.

Set up a Baserow database

Try this template

2. Use the row_id() function

Baserow automatically generates a row ID that uniquely identifies that row of data. The key value in a relational database should always be unique within its table because it allows each row in the table to be identified and accessed in a unique manner. This is important for ensuring data integrity and avoiding inconsistencies or errors in the database if the key value were to change.

Note: the row ID is not intended to count the number of rows in a table. When a row is deleted, the rows that remain are not renumbered. The assigned number is permanently attached to a row and cannot be changed or deleted once assigned to a row in the table, even after the row is deleted.

In the Staff table, create a field/column named Row ID. Make it a formula field and use the row_id() function as the formula.

Use the `row_id()` function

When you save that, you’ll see that every row in the Staff table has a unique value in the Row ID column.

3. Generate unique serial numbers with concat function

If a key value is not unique within its table, it can lead to data duplication or loss of data, as multiple rows may be assigned the same key value. This can also cause conflicts when trying to update or delete data in the table, as there may be multiple rows with the same key value.

The row ID generated by Baserow relies on the auto number functionality and thus may overlap across a number of tables. The number can be reused across multiple tables. It may cause issues in terms of the possibility of cross-table non-uniqueness.

To generate a unique identifier associated with each row and unique to the table, we will combine words or letters with the row ID. Even if numerous tables have the same number, the names will ensure each table has a distinct value.

Create a new formula field and input the formula: concat("B", row_id()).

Generate unique serial numbers with `concat` function

To enhance the efficacy and efficiency of your workflow, you can swap out “B” for another string and adapt your unique ID system to suit your needs.

Use the regex replace function to replace any text in the first input that matches the regex given by the second input with the text in the third input for additional randomization.

Key takeaways

With Baserow’s built-in formula, creating unique IDs for each row is a straightforward process. By following the steps outlined in this guide, you can easily create unique IDs for your Baserow table and take advantage of this feature to streamline your data organization and management.

In case you’ve run into an issue while following the tutorial, feel free to reach out to ask for help in the Baserow community.

What’s your use case? Tell us how you use Baserow