You are here: Re: ALTER column « PHP SQL « IT news, forums, messages
Re: ALTER column

Posted by Bob Stearns on 10/13/02 11:37

mick white wrote:
> I have a table `rhinos`
> +----------+-------------+------+-----+---------+-------+
> | Field | Type | Null | Key | Default | Extra |
> +----------+-------------+------+-----+---------+-------+
> | Day | varchar(20) | YES | | NULL | |
> | Date | varchar(20) | YES | | NULL | |
> | AwayTeam | varchar(30) | YES | | NULL | |
> | HomeTeam | varchar(30) | YES | | NULL | |
> | Time | varchar(20) | YES | | NULL | |
> | Venue | varchar(40) | YES | | NULL | |
> +----------+-------------+------+-----+---------+-------+
>
> I want to add " 2006" to the `Date` field;
>
> mysql> SELECT Day,Date from rhinos limit 2;
> +----------+--------+
> | Day | Date |
> +----------+--------+
> | Friday | Apr 21 |
> | Saturday | Apr 22 |
> +----------+--------+
> 2 rows in set (0.00 sec)
> mysql> ALTER TABLE rhinos set `Date`=CONCAT(`Date`," 2006");
> I've tried variations of this, to no avail.
>
> My ultimate goal is to convert the field to a real date type.
> Any pointers?
> Mick
>
You want UPDATE, a DML statement, not ALTER a DDL statement:

UPDATE rhinos set `Date`=CONCAT(`Date`," 2006");

But your longer term objective of changing field `date` to type 'date'
is a much more difficult task. In general, you can not change the type
of a column, so this will require an export, drop, create, import
sequence. Further external date representations are of the form
'yyyy/mm/dd' or 'mm/dd/yyyy', depending on your RDBM and its settings;
in particular, 'Mmm dd yyyy' is generally not allowed.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация