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

Creating Table in SQL

Question: Create a table called "products" with a VARCHAR column named "name", a TEXT column named "description" and a INTEGER "stock_count" column. The name should be up to 100 characters long.This is how I done it: CREATE TABLE products (name VARCHAR (100), description TEXT, stock_count INTEGER) I don't know what wrong with it.

14 Answers

@Umair - The issue is ultimately likely a flawed question. As Christopher mentions, using INTEGER is invalid SQL to begin with so hopefully they update this in the videos or questions. The solution to the problem would be as such:

CREATE TABLE products (
   name VARCHAR(100),
   description TEXT,
   stock_count INTEGER NULL
);

Though again, this should be INT and some value

Hi Umair,

There is no such "type" as INTEGER as far as I am aware. Try INT instead, that should work. For example:

CREATE TABLE `products` (
  `name` varchar(100),
  `description` text,
  `stock_count` int(11)
)
CREATE TABLE products ( name VARCHAR(100), description TEXT, stock_count INTEGER NULL );

This code works however if you messed up you have to refresh your browser (thus restarting all the challenges in this set.) or it will detect an error.

I have to agree with all there is a bug it worked for me in workbench without the NULL, However when I try it without the Null it says SQL Error: table products already exists . How can the table exist if am creating it ?????

''' CREATE TABLE products ( name VARCHAR(100), description TEXT, stock_count INTEGER NULL );'''

That code worked for me.

Challenge Task 1 of 2

Create a table called "categories" with a VARCHAR column named "name". The name should be up to 75 characters long.

CREATE TABLE IF NOT EXISTS categories (name VARCHAR(75));

Challenge Task 2 of 2

Create a table called "products" with a VARCHAR column named "name", a TEXT column named "description" and a INTEGER "stock_count" column. The name should be up to 100 characters long.

CREATE TABLE products (name VARCHAR(100), description TEXT, stock_count INTEGER NULL );

THIS THING IS BROKEN!!!!

I got by using the code from J Marston. It looks like the key is to use "NULL" at the end of INTEGER.

Update: when u get the error that the table exist try to drop it that worked for me, it seems that you are creating real tables in the background who knows.

Omh MG
Omh MG
19,233 Points

I got it with "NOT NULL" at the end. CREATE TABLE products (name VARCHAR(100), description TEXT, stock_count INTEGER NOT NULL);

Chris Bagi
Chris Bagi
25,737 Points

None of the above worked for me.

The problem is IF you've attempted and it returned an error and you try again with one of the above solutions it says "the table already exists" meaning your first attempt created a table but with parameters outside of the scope of the question. Restart the code challenge and Yan Cruz, Christopher Geary, and J Marston's answers all work as I have tested.

Treehouse needs to fix the code challenges to check IF the code first meets the requirements and then execute, currently it executes and then checks if the parameters of the question were met.

Anyone figure this out?

Edgar Gil
Edgar Gil
13,322 Points

Always check that you write

INTEGER

An Not

INTERGER