[MYSQL] Making default value calculated

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[MYSQL] Making default value calculated

Jolle Carlestam
Can a field in Mysql be default populated by a calculated result when  
creating new records?

Something like this:

ALTER TABLE `testing`
        ADD `result` VARCHAR (255) NOT NULL DEFAULT (field1 + ": " + id);

I know that I could prepare the content of the field in Lasso but I  
want to combine the content of a field populated by lasso with an  
autoincremented field. And that field wont have any content until  
Mysql populates it.

HDB
JC

--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/

Reply | Threaded
Open this post in threaded view
|

Re: [MYSQL] Making default value calculated

Steffan A. Cline
No, you cannot do that. You will need to look into triggers. An update will
trigger a stored procedure to do this for you.

http://dev.mysql.com/doc/refman/5.1/en/triggers.html


Thanks

Steffan

---------------------------------------------------------------
T E L  6 0 2 . 5 7 9 . 4 2 3 0 | F A X  6 0 2 . 9 7 1 . 1 6 9 4
Steffan A. Cline
[hidden email]                             Phoenix, Az
http://www.ExecuChoice.net                                  USA
AIM : SteffanC          ICQ : 57234309
                                  Lasso Partner Alliance Member
---------------------------------------------------------------



> From: Jolle Carlestam <[hidden email]>
> Reply-To: Lasso Talk <[hidden email]>
> Date: Sat, 7 Jul 2007 08:36:45 +0200
> To: Lasso Talk <[hidden email]>
> Subject: [MYSQL] Making default value calculated
>
> Can a field in Mysql be default populated by a calculated result when
> creating new records?
>
> Something like this:
>
> ALTER TABLE `testing`
> ADD `result` VARCHAR (255) NOT NULL DEFAULT (field1 + ": " + id);
>
> I know that I could prepare the content of the field in Lasso but I
> want to combine the content of a field populated by lasso with an
> autoincremented field. And that field wont have any content until
> Mysql populates it.
>
> HDB
> JC
>
> --
> This list is a free service of LassoSoft: http://www.LassoSoft.com/
> Search the list archives: http://www.ListSearch.com/Lasso/Browse/
> Manage your subscription: http://www.ListSearch.com/Lasso/
>



--
This list is a free service of LassoSoft: http://www.LassoSoft.com/
Search the list archives: http://www.ListSearch.com/Lasso/Browse/
Manage your subscription: http://www.ListSearch.com/Lasso/