Reputation: 1019
i have a table which have 3 column ID, Fname, Lname when i insert data in two column fname and Lname then Id will automatically generated and inserted in ID column that is first 3 char of Fname Column and then underscore and first char of Lname "id may be duplcate" for cancate i use
Select Concat(Left(Fname,3),'_',Left(Lname,1));
Fname Lname ID
Ashutosh Singh Ash_S
Upvotes: 0
Views: 154
Reputation: 767
USE integer as PK.
create table users(
id serial,
my_key varchar(5),
fname varchar(50),
lname varchar(50)
);
first 3 char of Fname Column and then underscore and first char of Lname could not be unique
my_key can be filled by on "insert" trigger - .
Upvotes: 1
Reputation: 217
I think you need to make a trigger on insert action so that it fills the ID column using the business logic you mentioned
Upvotes: 0