Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools

Kevin Naegele
Kevin Naegele
10,868 Points

how do you find whats causing the syntax error. Work bench only underlines the closing ");" MySQL

create table sampdb.pres_term ( foreign key (pres_id) references president (pres_id), term start date date, term End date date, number of elections won integer, reason for leaving office varchar(255), term_id INT unsigned not null AUTO_INCREMENT, primary key (term_id), );

6 Answers

William Dahl
William Dahl
7,829 Points

Hi Kevin,

It appears the work bench is telling you that the closing ");" is not what was expected.

If you look immediately before that, you will see that you had a comma. A comma indicates you are going to list more items. What the compiler does then, is look at the next characters to see what the next field name is. Therefore you would want to remove the last comma.

Take a look at this example:

CREATE TABLE Persons
(
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
);

/* Sourced from: http://www.w3schools.com/sql/sql_create_table.asp
*/

Also note: for a given field (or column name) you want to indicate the field name and then the data type. If you have multiple words then the compiler won't know which is which. So for a field like "number of elections won integer", you might write it as one of these:

number_of_elections_won integer,
numberOfElectionsWon integer,
ElectionsWon integer
Kevin Naegele
Kevin Naegele
10,868 Points

I agree with the title, I am taking an MySQL class and the teacher not helping me out and there is no tutors that know it. I have to have those names. PS tree house has been way better way to learn....

William Dahl
William Dahl
7,829 Points

Hi Kevin,

I agree that treehouse is great to learn. Much more effective than when I was at uni.

But on topic:

If you must have those table names it is possible (but not recommended) to write them like this:

"number of elections won" integer

By having quotation marks around the table name, the compiler will treat it as a single string - thereby allocating that as the table name.

What this means however is that in future, all references to this table will require quotation marks. If you do this in a complex business database - people having to work with it afterwards will get frustrated.

Kevin Naegele
Kevin Naegele
10,868 Points

I thougt i was supposed to number of elections won not the "number of elections won"

William Dahl
William Dahl
7,829 Points

Sorry just checked, it may vary by database system.

If quotation marks don't work, you may be able to do it like this:

[Percentage mark] integer,