Ivan Tyler
Ivan Tyler

Reputation: 23

How to auto increment another column in sql when the primary key is auto incremented?

I have a table to store the customer details. I need to add a new column to give these customers or new customers a unique auto increment ID to identify them and also need the primary key to keep the count of the customers.

I already have primary key AI to display the number of customers. I Googled and learned that only primary key can be auto incremented. So how can I achieve this?

I need the customer ID to be of only number of about 5-10 digits. Something like this: uid = 232100001. It should start from one number and auto increment when the primary key is auto incremented.

Upvotes: 0

Views: 122

Answers (1)

Memos Electron
Memos Electron

Reputation: 660

I am using TRIGGERs to keep track of the count of such things

More infos you can find here

For example you can create another table with the name counters on which with the trigger will update the registered_users column when a user is added or deleted.

For the IDs of the users you just make the primary key start from a specific value. An answer for this is given on another question here.

Upvotes: 0

Related Questions