Solved

MySQL Substring Default

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with a query 6 75
SQL inner join confusion 15 54
sql_mode 1 26
Restore of mysql database from .SQL file - using Coldfusion 5 37
As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 …

825 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