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 Database Foundations Creating Tables and Manipulating Data with SQL Creating a Table

M Z
PLUS
M Z
Courses Plus Student 4,784 Points

Trying to build a db and I can't create this table, I have no idea why. Please help

CREATE TABLE IF NOT EXISTS stamps (stamp1a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp2a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp3a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp4a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp5a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp6a DATE_FORMAT(DATE,'%d-%m-%Y'), free_a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp1b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp2b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp3b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp4b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp5b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp6b DATE_FORMAT(DATE,'%d-%m-%Y'), free_b DATE_FORMAT(DATE,'%d-%m-%Y'), stamp1c DATE_FORMAT(DATE,'%d-%m-%Y'), stamp2c DATE_FORMAT(DATE,'%d-%m-%Y'), stamp3c DATE_FORMAT(DATE,'%d-%m-%Y'), stamp4c DATE_FORMAT(DATE,'%d-%m-%Y'), stamp5c DATE_FORMAT(DATE,'%d-%m-%Y'), stamp6c DATE_FORMAT(DATE,'%d-%m-%Y'), free_c DATE_FORMAT(DATE,'%d-%m-%Y'));

Logan R
Logan R
22,989 Points

What is the error message?

M Z
M Z
Courses Plus Student 4,784 Points

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 'DATE_FORMAT(DATE,'%d-%m-%Y'), stamp2a DATE_FORMAT(DATE,'%d-%m-%Y'), stamp3a DA' at line 1

Ken Alger
Ken Alger
Treehouse Teacher

In what database and version are you working?

1 Answer

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Mehran;

DATE_FORMAT is not a valid data type, but is a function. So, when you create the table you would have:

CREATE TABLE IF NOT EXISTS stamps (stamp1a DATE, stamp2a DATE, ...

Then when you pull the data out of the database and want to display it you would utilize the DATE_FORMAT function to determine how the data looks in the report.

As an aside, you probably would want to include a key of some sort in your table as well that auto increments.

Ken