How to make MySQL table primary key auto increment with some prefix with current year -


i have table this

create table student(   `regdno` varchar(20) not null auto_increment,   `name` varchar(30) not null,   `fathername` varchar(30) not null,   `dob` varchar(30) not null,   `course` varchar(30) not null,   `address` varchar(100) not null,   `contacthome` varchar(30) not null,   `contactpersonal` varchar(30) not null,   `coursefee` int(20) not null,   primary key (regdno) ) 

i want increment id field '25/yerar/200','25/yerar/201','25/yerar/202'... etc. should have that? please let me know possible way.

dont try that, instead better idea

create table student(   `regdno` int not null auto_increment,   `regdno_fluf` varchar(20) not null,   //<- new col stuff   `name` varchar(30) not null,   `fathername` varchar(30) not null,   `dob` varchar(30) not null,   `course` varchar(30) not null,   `address` varchar(100) not null,   `contacthome` varchar(30) not null,   `contactpersonal` varchar(30) not null,   `coursefee` int(20) not null,   primary key (regdno) ) 

now let mysql deal autoincrementing regdno normal , use regdno_fluf column store whatever fluf want use.

all when come present needs fluf, concatenate regdno either in query run or in language using application

select concat(`regdno_fluf`,'/',`regdno`) fluffed_regdno, ..... 

but foreign key links may want create still use nice , simple regdno


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -