PDA

View Full Version : adding new field to table that already exists??


SpeedFreak
06-28-2003, 12:12 PM
hey,

here is the syntax i used to create a table with certain fields:

CREATE TABLE article (
id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
section_id int(10) unsigned DEFAULT '0' NOT NULL,
category_id int(10) unsigned DEFAULT '0' NOT NULL,
approved enum('N','Y') DEFAULT 'N' NOT NULL,
title varchar(100) NOT NULL,
author varchar(50) NOT NULL,
email varchar(50) NOT NULL,
date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
PRIMARY KEY (id),
KEY id (id, section_id, category_id)
);



now since i have done that i want to add a few new fields:

INSERT INTO TABLE article(
score ??? unsigned DEFAULT '0' NOT NULL,
genre varchar(50) NOT NULL,
fuser varchar(50) NOT NULL,
);


firsty, is the above syntax correct (i just want to add new fields, not delete any existing ones or their content)?
secondly for the field 'score' that will be a 2 digit number but not an integer (will have decimal place) - what do i put instead of ??? there?

Thanks

cpradio
06-28-2003, 04:05 PM
ALTER TABLE article
add score ??? unsigned DEFAULT '0' NOT NULL,
add genre varchar(50) NOT NULL,
add fuser varchar(50) NOT NULL
;

-Matt

SpeedFreak
06-28-2003, 04:47 PM
thanks for that matt :thumbsup:

as for my second question - does anyone know what i'd use in place of ??? to describe a 2 digit number thats not an integer (it has decimal place)??

thanks :)

cpradio
06-28-2003, 05:01 PM
DECIMAL(10,2)

SpeedFreak
06-28-2003, 08:49 PM
Originally posted by cpradio
DECIMAL(10,2)

w00t - thanks mate :thumbsup: :cool: