0

First time working with MySQL. Using MySQL Workbench with a new instance installed on my Windows 10 desktop. I've created a test test db/schema, and now trying to create a table.

CREATE TABLE kcplusers (
'user_barcode' varchar(255),
'first_name' varchar(255),
'middle_name' varchar(255),
'last_name' varchar(255),
'address_street' varchar(500),
'city_state' varchar(500),
'zip' varchar(100),
'user_profile' varchar(500),
'birth_date' DATE
);

Workbench shows a red x at line 1 and red slashes under the open-parenth (

I get the error:

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 ''user_barcode' varchar(255), 'first_name' varchar(255), 'middle_name' varc' at line 2

What am I missing?

Ibu
  • 42,752
  • 13
  • 76
  • 103
  • See https://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql – Bill Karwin May 29 '19 at 18:32

2 Answers2

4

Don't use single quotes ' for the fields names, use backticks ` or nothing at all:

CREATE TABLE kcplusers (
`user_barcode` varchar(255),
`first_name` varchar(255),
`middle_name` varchar(255),
`last_name` varchar(255),
`address_street` varchar(500),
`city_state` varchar(500),
`zip` varchar(100),
`user_profile` varchar(500),
`birth_date` DATE
);
Ibu
  • 42,752
  • 13
  • 76
  • 103
1

You're using apostrophes around the column names - they should be removed in this case.
If you must specify certain characters in a column name you can use ascii cd 96 shown as ` - usually just to the left of the number "1" on your keyboard.
But to keep it simple as you're starting out - just remove the apostrophes. And let us know how it turns out (good or bad) Cheers!

Pete Kelley
  • 3,713
  • 2
  • 16
  • 17