Archive for the ‘Database’ Category

Adding index for a table

August 3, 2007

In Excel:

Approach #1: In the cell 1 of the index row, type in “1″ and cell 2, type in “2″. Select both cells. Excel highlights both cells with bold-stroked box. There is a small handler on the bottom-right corner (Supposed to be a feature called “Auto Fill”?) Hold and drag the handler all the way down to the last cell on the index row. Excel should autofill all the rest of the cells.

Approach #2: In the cell 1 of the index row, type in “1″. In cell 2, type in “=ROW_NUM1+1″ (For example, if this is row A, type in “=A1+1″. What this formula does is to increment the value of cell 1 by 1, which equals to 2.) Select cell 2; drag the small handler on the bottom-right to all the way down the last cell.

In MySQL:

Approach #3: Create a column which is primary key, data type of int and attribute of AUTO_INCREMENT.

convert string into date

June 23, 2007

I wanted to convert a column whose data type of string into that of date.

First add a column with data type of date;

Then:

UPDATE `myTable` SET `REALDATE`= str_to_date( `SRTDATE` , '%m/%d/%Y' );

This will convert ‘06/23/2007′ in STRDATE into ‘2007-06-23′ in REALDATE.

How to copy columns from one table into another table

May 8, 2006

Example:

INSERT INTO staff( firstName, lastName, address, homePhone, cellPhone, latitude, longitude )
SELECT firstName, lastName, address, homePhone, cellPhone, latitude, longitude
FROM gfxContact

Data normalization

May 6, 2006

I read about “database normalization” today in the book “PHP Essentials”, which introduces three of the five (?) “normal forms”. I don’t quite get it but I am glad that I came across it :)

I got some similar articles when smart googling “database normalization”. Here are some of them: