Prevent Duplicate Document Number

I am working on a helpdesk ticketing system. When a user submits a ticket I want to assign the ticket a unique number, for example: 20190724001 where the first four digits is the year, next two are the month, next two the day and the last three would be the next consecutive number FOR THAT DAY and then the numbering would start back at 1 the next day. I know to query the table for the next number where the date equals today, but I do I obtain the next consecutive number without another user…

Prevent Duplicate Document Number