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 trialNils Garland
18,416 PointsSQL database problem
I tried to enter this in the structure, but it gave me an error
my code:
CREATE TABLE IF NOT EXISTS 'users' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'username' varchar(255) NOT NULL,
'first_name' varchar(255) NOT NULL,
'last_name' varchar(255) NOT NULL,
'email' varchar(255) NOT NULL,
'password' varchar(32) NOT NULL,
'sign_up_date' date NOT NULL,
'activated' enum('0','1') NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
The error:
#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 ''users' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'username' varchar(255) NOT ' at line 1
2 Answers
Chaz Watkins
9,879 PointsHi Nils,
After doing a bit of research on the MySQL Manual, it seems the syntax being used was incorrect. I removed the quotations from your table/column names.
The below should work for you:
CREATE TABLE IF NOT EXISTS users (
id int(11) NOT NULL,
username varchar(255) NOT NULL,
first_name varchar(255) NOT NULL,
last_name varchar(255) NOT NULL,
email varchar(255) NOT NULL,
password varchar(32) NOT NULL,
sign_up_date date NOT NULL,
activated enum('0','1') NOT NULL,
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
Devron Baldwin
3,508 PointsHi Nils Garland
The answer Chaz Watkins gave will work for you but the reason your code doesn't work is that you need to use backticks instead of single quotes. The backtick is ` whereas the single quote is '.
It depends on your keyboard layout but often the backtick is found on the key to the left of the 1 key on a keyboard.
Replacing the single quotes with backticks give you the following code:
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(255) NOT NULL,
`first_name` varchar(255) NOT NULL,
`last_name` varchar(255) NOT NULL,
`email` varchar(255) NOT NULL,
`password` varchar(32) NOT NULL,
`sign_up_date` date NOT NULL,
`activated` enum('0','1') NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
I've tested this and it works.
Nils Garland
18,416 Pointsoooh okay they are so simular, thank you anyway :D!
Nils Garland
18,416 Pointsoooh okay they are so simular, thank you anyway :D!
Nils Garland
18,416 PointsNils Garland
18,416 PointsThanks a lot, it works! :D