sql - Create a computed column based on another column in MySQL -


i have 2 columns in table: varchar(8) , int.

i want auto-increment int column , when do, want copy value varchar(8) column, pad 0's until 8 characters long, example, if int column incremented 3, varchar(8) column contain '00000003'.

my 2 questions are, happens when varchar(8) column gets '99999999' because don't want have duplicates?

how in mysql?

if values can between 00000000 99999999, how many values can have before run out?

this alternative approach creating random 8 character string , checking mysql duplicates. thought better approach , allow greater number of values.

because formatted column depends upon, , derivable from, id column, table design violates 3nf.

either create view has derived column in (see in sqlfiddle):

create view myview select *, substring(cast(100000000 + id char(9)), 2) formatted_id mytable 

or start auto-increment @ 10000000, 8 digits long:

alter table mytable auto_increment = 10000000; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -