?
Solved

MySQL Substring Default

Posted on 2011-03-08
4
Medium Priority
?
445 Views
Last Modified: 2012-05-11
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
0
Comment
Question by:hungoveragain
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:mayankagarwal
ID: 35068611
you can create view on the main table to achieve the same
0
 
LVL 5

Accepted Solution

by:
mayankagarwal earned 1500 total points
ID: 35068621
create table names (
name varchar(256) not null)

create view v_names as select name , shortname substring(name,1,7) from names
)




0
 

Author Comment

by:hungoveragain
ID: 35069195
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
0
 

Author Closing Comment

by:hungoveragain
ID: 35069791
Solution did not fully solve the problem but no other solutions were given.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question