Forum Moderators: open

Message Too Old, No Replies

Insert a new field (newbie)

         

internetheaven

12:57 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I inserted this a few months ago:

CREATE TABLE `tbllinks` (
`CatID` int(11) NOT NULL default '0',
`Date` date NOT NULL default '0000-00-00',
`LinkID` int(11) NOT NULL auto_increment,
`WebAddr` varchar(100) NOT NULL default '',
`LinkText` varchar(50) NOT NULL default '',
`Description` varchar(250) NOT NULL default '',
`PageUrl` longtext NOT NULL,
PRIMARY KEY (`LinkID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

and what I want (if I were creating from scratch) would be this:

CREATE TABLE `tbllinks` (
`CatID` int(11) NOT NULL default '0',
`Date` date NOT NULL default '0000-00-00',
`LinkID` int(11) NOT NULL auto_increment,
`WebAddr` varchar(100) NOT NULL default '',
`LinkText` varchar(50) NOT NULL default '',
`Description` varchar(250) NOT NULL default '',
`PageUrl` longtext NOT NULL,
`contactEmail` varchar(128),
PRIMARY KEY (`LinkID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=82 ;

How do I insert the contactEmail value into the already existing database?

Thanks for your help
Mike

Habtom

1:03 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to update the existing data.

UPDATE tbllinks SET contactEmail = 'email@example.com'

BUT

if you wish to have a different email assigned to the rows, you need to write as many update statements or find a different to do it through loops, and the query will look like this:

UPDATE tbllinks SET contactEmail = 'email@example.com' WHERE CatID = '1'

UPDATE tbllinks SET contactEmail = 'email2@example2.com' WHERE CatID = '2'

. . .

Habtom

Habtom

1:06 pm on Nov 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, reading back what you posted, you are looking for this SQL statement:

alter table tbllinks add column contactEmail varchar (128) ;

Habtom