Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lampone's avatar

MySQL Design Customer Table - Customer ID

I hope someone can help me with my Database Design. I have a table customers where all customers are stored, while they can be of a different type. The type would be "client" or "lead", indicating if it is a actual customer or just a lead.

Now i need a unique CustomerId that is auto-incrementing but only for clients and not for leads. I can't take the id since that value is incrementing for clients and leads.

Did someone solve a similar issue before and give me a approach to getting a incrementing customer-number?

0 likes
7 replies
D9705996's avatar

@Lampone - I would create two tables, one for Customers and one for Leads and then in you application if a lead becomes upgraded to a customer you can codd the logic.

You are still going to need an id on each record in your database as this is how each record is uniquely identified.

Lampone's avatar

@D9705996 It was my first idea, but they have so many relations in common and both store the same data in the table. It felt kind of wrong to have 2 tables.

Thanks for your input.

D9705996's avatar

If you have lots of duplication then you would want to find a name to describe a third table that you could use to store the shared data e.g. Person

You can then relate your lead/customer to the person model

You could also look at this blog on sub types of models

https://tighten.co/blog/extending-models-in-eloquent

Just bear in mind you need id's on all your models so you can uniquely identify them

manelgavalda's avatar

I agree with @Lampone, but in case you need the different type of users in the same table, I would create a UserObserver and in the created method update your auto-increment field (just if the user is of type client) with the count of all client users (withTrashed to avoid duplicated fields when restoring deleted clients).

To do something like this without being gross you can use this package https://github.com/tightenco/parental because it let you manage easy different type of users using Single Table Inheritance.

Lampone's avatar

Single Table Inheritance is what I used until now (without knowing the name :) ) @globals thanks for package suggestion

I didn't want to use the manual incrementing field, because I would like to be able to delete leads permanently. Since the gdpr is in effect I would rather be safe than sorry.

Maybe @D9705996 suggestion with a related model to store the status (client/lead) could work. Trying to wrap my head around it...

D9705996's avatar

@Lampone - not having an incrementing id will not help you with GDPR compliance as the personally identifiable information is still stored in your database. To be honest GDPR is an absolute minefield.

You might want to look at some laravel specific GDPR packages that help with anonymising data e.g.

https://github.com/dialect-katrineholm/laravel-gdpr-compliance

With GDPR If you are not sure take expert advice as the penalties for non compliance are severe, and I don't mean asking here - find a reputable specialist online.

Lampone's avatar

@D9705996 i will still have an incrementing id. The customer number would only be incrementing and unique for the business logic.

I know that GDPR is quite a handfull, but luckily the app is only internal and not for public use. So thats on less thing to worry about :)

I have a expert at hand, and will go discuss everything once the app is finished.

1 like

Please or to participate in this conversation.