Creating a Auto Generation ID with Prefix in MySQL Without Using Trigger
I need Creating a Employee Id with Prefix and Without Using Trigger in MySQL.
Creating a Auto Generation ID with Prefix in MySQL Without Using Trigger
I need Creating a Employee Id with Prefix and Without Using Trigger in MySQL.
2
Answers
To create an auto-generated employee ID with a prefix in MySQL without using triggers, you can follow one of the approaches below:
You can use the AUTO_INCREMENT feature in MySQL to automatically generate unique IDs for your employees.
You can create a computed column that combines the prefix and an auto-incremented value.
Choose the approach that best fits your requirements, and adjust the table and column names as needed. Remember to replace ‘EMP’ with your desired prefix.
The first paradigm looks fine to me. On the second one i think, that’s not a correct syntax for MySQL.
However to use generated columns, you can choose between two opportunities: Virtual / Stored.
MySQL : 15.1.20.8 CREATE TABLE and Generated Columns
My read is, the example (on using the above described example, part 2) will use stored columns:
This is a very simple example so far. For the further development, i strongly recommend to check (for your intention) the datatypes and boundaries.