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

Adam Duffield
Adam Duffield
30,494 Points

Issues with an SQL INCREMENT KEYS task

Task is: Create a genres table called "t_genres" with an auto incrementing primary key called "pk_id" and a unique column called "uk_name" that can't be null. The "uk_name" is a varchar of up to 45 characters.

My code:


Really struggling to follow all this Key stuff and what it's actually doing, any help would be much appriciated!

3 Answers

Did you add the "NOT NULL UNIQUE KEY" part??

in your code the part that is wrong is when you define the first column.

In your code you start the brackets and then use 2 names for the first column....first "id" then "pk_id".

(id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY pk_id, Rest of your bracket)

so this is kind of like naming the first column "id" and "pk_id" at the same time.

change it to (pk_id INTEGER (..rest of the code...) PRIMARY KEY, uk_name VARCHAR(45) (..rest of the code...) );

without "id" !!

About the keys. The PRIMARY KEY makes sense because with it you can later reference it in another table. You could use different tables with different movies and always give the movies a FOREIGN KEY which stands for the key of the genre....

f.e. action has pk_key of 1....then every other table that has a action movie you just need to add a FOREIGN KEY with 1 and it will be labeled as an actionFilm. The point of that whole thing is, that if you like to change the genre...for example use it in another language....you don;t need to change every single movie , instead you change it in the genres tale and because of the keys every film gets automatically updated.

The unique key for name is just to make sure that no genre has the same name. Hope that makes some sense ;-)

Adam Duffield
Adam Duffield
30,494 Points

Hey, Sorry for the late reply! That kinda make's sense yeah, I can see why it's important to include keys in a database but I'm still not getting the task completed.

My code at the moment SQL CREATE TABLE t_genres (pk_id INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY, uk_name VARCHAR(45));

Error message says: Bummer! There's something wrong with the definition of your column named 'uk_name'.