Solved

MySQL Substring Default

Posted on 2011-03-08
4
419 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
  • 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

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…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now