Link to home
Start Free TrialLog in
Avatar of hungoveragain
hungoveragain

asked on

MySQL Substring Default

Is there any way to create a column that defaults to a substring of another column?

create table names (
name varchar(256) not null,
shortname varchar(7) not null default substring(name,1,7)
)

Thanks

Mike
Avatar of mayankagarwal
mayankagarwal
Flag of India image

you can create view on the main table to achieve the same
ASKER CERTIFIED SOLUTION
Avatar of mayankagarwal
mayankagarwal
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hungoveragain
hungoveragain

ASKER

That's a nice idea, however I need to be able to update the column based on possible user input

insert into names (name,shortname) values ('Robert Louis Stevenson','Bob')
resolves "Robert Louis Stevenson" - "Bob"

insert into names (name) values ('Robert Louis Stevenson')
resolves "Robert Louis Stevenson" - "Robert "

Any other ideas?

Thanks

Mike
Solution did not fully solve the problem but no other solutions were given.