Reputation: 13
I have been successful in adding a new column to my table in MySQL. However I can't seem to add any data to it. I have tried using an UPDATE
but I get an error. I am including the original code for the table, and the ALTER
that added the column and the attempted update.
CREATE TABLE `Teams` (
`Team_id` INTEGER unsigned NULL AUTO_INCREMENT DEFAULT NULL,
`team name` VARCHAR(50) NULL DEFAULT NULL,
`league` CHAR(2) NULL DEFAULT NULL,
`div` VARCHAR(15) NULL DEFAULT NULL,
PRIMARY KEY (`Team_id`)
);
the filling (abbreviated)
INSERT INTO `Teams` (`team name`,`league`,`div`) VALUES
('Free Agent','',''),
('Blue Jays','AL','East'),
('Yankees','AL','East'),
('Orioles','AL','East'),
...and so on
The ALTER
:
ALTER TABLE Teams
ADD City VARCHAR(20);
The UPDATE
:
UPDATE Teams
SET City='NONE' where (team name='Free Agent');
Upvotes: 0
Views: 64
Reputation: 44581
You should escape identifiers if they contain spaces:
UPDATE `Teams`
SET `City`='NONE' where (`team name`='Free Agent');
Upvotes: 2