Reputation: 289
I'm working through the head first SQL book using MySQL and am encountering an error when trying to run the code in the book. I'm sure the error is very obvious but it has me stumped. The idea is to add a primary key to the table project_list by changing the name of a current column and setting it as a primary key.
ALTER TABLE project_list
CHANGE COLUMN number proj_id INT NOT NULL AUTO_INCREMENT,
ADD PRIMARY KEY ('proj_id');
Error message:
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''proj_id')' at line 3.
Upvotes: 0
Views: 28
Reputation: 881423
ADD PRIMARY KEY ('proj_id')
is attempting to set the primary key to a literal string rather than a column. You should either use proj_id
on it's own:
... ADD PRIMARY KEY (proj_id);
or the back-tick version (with `
rather than '
):
... ADD PRIMARY KEY (`proj_id`);
Upvotes: 1