I want to create a new column that has a default value of the primary key in a varchar(10) format. Hows this done?
| SitePoint Sponsor |

I want to create a new column that has a default value of the primary key in a varchar(10) format. Hows this done?
<?php//Kyle Wolfeecho devBlog("My Dev Notes");


it's not done -- you cannot assign a default value of another column
why not just convert the value when you run a SELECT?
or, if you're gonna do it relentlessly on every SELECT, why not set up a view which has the extra column incorporated?
You're duplicating data though, why would the pk value not suffice?
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

Our large dataset needs compared regularly against two seperate databases, One stores the pk as a double, the other as a string (wonderful right?) Our local copy of the dataset is only a small portion of the whole system so storing both types of primary keys for joining to both seemed useful.
<?php//Kyle Wolfeecho devBlog("My Dev Notes");
Ah, I see. A view, as R937 states, sounds like it could be useful here then.
@AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

Ah nice. Had not seen or heard of views before now. Thanks for that pointer.
<?php//Kyle Wolfeecho devBlog("My Dev Notes");
Bookmarks