Solved

MySQL Substring Default

Posted on 2011-03-08
4
430 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 500 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
I have been using r1soft Continuous Data Protection (http://www.r1soft.com/linux-cdp/) for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

749 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