Question : MySQL create table question ........ default value for a field

Hi guys hope u are all well and can help me with a create table question for MySQL.

Here is my current create table design.....................................................

CREATE TABLE  subiframes_sif (
  id_sif int(11) NOT NULL auto_increment,
  url_sif varchar(255) NOT NULL,
  subiframeurl_sif varchar(255) NOT NULL,
  code_sif text,
  description_sif text,
  PRIMARY KEY  (id_sif),
  UNIQUE KEY url_sif (url_sif)
)
---------------------------------------------------------------------------------------------------

If I do a select all on this table, it looks like the following..................................

select id_sif, url_sif from subiframes_sif;

id_sif    url_sif                                                               subiframeurl_sif              
----------------------------------------------------------------------------------------------------
1          menu2_sandbox1_example.php


############
WHAT ID LIKE:
############

Id like the value for column subiframeurl_sif  to be autopopulated, like a default so to speak, by doing the following....
1) Look at the corresponding value of the column url_sif
2) Grab this value, and strip off the .php in its name
3) Append a '_subiframe.php' to the value that is left after step 2)
4) Insert this value from step 3) into the field for subiframeurl_sif

##########
EXAMPLE:
##########

id_sif    url_sif                                                               subiframeurl_sif              
----------------------------------------------------------------------------------------------------
1          menu2_sandbox1_example.php

In the above, the value for row 1 in column subiframeurl_sif would be:

menu2_sandbox1_example_subiframe.php

So,

select id_sif, url_sif from subiframes_sif;         would result in:

id_sif    url_sif                                                               subiframeurl_sif              
----------------------------------------------------------------------------------------------------
1          menu2_sandbox1_example.php                      menu2_sandbox1_example_subiframe.php


Id like this done on my create table design, so that this would be the default value for subiframeurl_sif for any new records inserted

Any help greatly appreciated. :>)

Answer : MySQL create table question ........ default value for a field

update TABLE set subiframeurl_sif=replace(url_sif ,'.php','_subiframe.php')
Random Solutions  
 
programming4us programming4us