Auto-increment column

How to create a function that can auto-increment unique id for each record insertion in Db table.
I want to insert name, phone number, email into a table in which one column that can auto increment the column with unique values.
Ex: Table name - ticket_details
Columns- Ticket id, user name, phone number, email.
I want the ticket id for each insertion to be unique value with auto incremented.

Please provide the sample code function to write .

hi any update for the above ?

@Monisha_S @Aakanksha

Hi @Nikhitha,

You can create a custom Logic function to create a unique value. Here is an example code:

return new Promise(async resolve => {
    // Your logic goes here
    function randomString(length, chars) {
        let result = '';
        for (let i = length; i > 0; --i){
            result += chars[Math.floor(Math.random() * chars.length)];
        return result;
    let uniqueGiftCardID = "TID_" + await randomString(5, '0123456789abcdefghijklmnopqrstuvwxyz');

Once this unique value is generated, You have to check whether this unique value exists in your Database Table or not.

If it doesn’t exist in your Database Table, You can insert the required details along with this unique value into your Database Table.

It the unique value exists in your Database Table already, run the function again to create another unique value. Make sure to follow the same process so that your unique value will not have a duplicate value in your current DB Table.

The above process have to followed only once at the beginning.

Once you have inserted 1 record successfully with a unique value, the next time you want to insert another record, Fetch the latest record in the DB Table and get that unique value.

Now by creating another custom function, you can increment this unique value which you got from the latest record of your DB Table.

Just to be double sure, Do a Database Search with this incremented unique value.

If the Incremented unique value is present on the DB Table, Do an Increment again for the current unique value.

If the Incremented unique value is not present on the DB Table, You can proceed further and insert the required values along with with the incremented unique value into your DB Table.

Thus, You can create a DataBase Table with auto-incremented unique value for each record.

Feel Free to let me know if you have any questions on the same.