Thread: 2 questions
View Single Post

   
  #3 (permalink)  
Old 05-02-2008, 05:05 AM
Rik Wasmus
 
Posts: n/a
Default Re: 2 questions

On Thu, 01 May 2008 00:59:59 +0200, F Tahbaz <ftahbaz@gmail.com> wrote:

> 1) How can I insert a column into my table DATA, and make it my
> primary key (that will just be a number starting at 1 and increasing n
> +1)...


ALTER TABLE data ADD COLUMN id int PRIMARY KEY AUTO_INCREMENT FIRST;

> 2) I have a column named DATEID in a table DATA that contains the
> following format connected to each other(date and name):
>
> 20071030Jones
> 20071020Smith
> 20070918Rogers
> 20080122Williams
> etc..
>
> What would the syntax be to insert a column to the right of this one,
> and extract the first 8 digits from the data in the DATEID column and
> insert that into the new column DATE, therefore making it easier for
> me to query against an actual date?


IF the DATEID column is reliable:
UPDATE TABLE data ADD COLUMN datefld DATE NOT NULL AFTER dateid;
ÚPDATE data SET datefld = DATE(SUBSTRING(dateid,0,9);
--
Rik Wasmus
Reply With Quote