MySQL syntax error, can't figure out what's wrong - mysql

Hello and thanks for reading my question! I am receiving a syntax error with this code but I cannot figure out what's wrong. Any insight is greatly appreciated.
mysql> create table match (
-> event_id int not null,
-> player1_id int,
-> player2_id int,
-> player1_score int,
-> player2_score int,
-> winner_id int,
-> foreign key (event_id) references event(id)
-> );
ERROR 1064 (42000): 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 'match (
event_id int not null,
player1_id int,
player2_id int,
player1_score int' at line 1
I can't find any missing commas, and the event table definitely exists with an id column. Any ideas what I'm missing? Thank you!

Match is a reserved word. Enclose it in backticks:
create table `match` ...

Related

mySQL - create table error 1064(42000): syntax error

I'm trying to create the table below but I get an error. I double checked and the data types are valid, and a table with this name doesn't currently exist in the database. I even closed and re-opened my terminal in case this was a glitch. But still no luck. Any idea what's wrong here?
create table order (order_no int, purch_amt decimal(6,2), order_date date, customer_id int, salesman_id int);
Error message I get:
ERROR 1064 (42000): 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 'order (order_no int, purch_amt decimal(6,2), order_date date, customer_id int, s' at line 1
order is SQL keyword. I would suggest calling the table orders. I would suggest:
create table orders (
order_no int,
purch_amt decimal(6,2),
order_date date,
customer_id int,
salesperson_id int
);

ERROR 1064 (42000) in creating table using MySQL 8.0 command line

I'm trying to create a table Order but somehow I am encountering the error code below:
ERROR 1064 (42000): 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 'Order(
OrderId int,
CustId int,
OrderDate datetime,
RequiredDate datetime,
Shipp' at line 1
I use the following code to create my table:
create table Order(
-> OrderId int,
-> CustId int,
-> OrderDate datetime,
-> RequiredDate datetime,
-> ShippedDate datetime,
-> Status varchar(12),
-> Comments varchar(255)
-> );
We don't need to set primary key or foreign key but I don't know what went wrong with my code. Please advice thanks!
Thanks #jarlh I didn't know it was a reserve word. I just started SQL.

MySQL error 1064 table creation

This seems a fairly trivial problem but I am having no luck in running the following query:
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR(20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
When I run this I get the following error message:
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 '(20), retweet_count INT, favourite_count INT,
tweet_followers_count ' at line 3
When I hover over the error tag on line 3 it says:
Syntax error : unexpected '(' (opening parenthesis)
I'm sure this is a simple fix, any help would be great!
Turned out to be an error with mySQL Workbench
create table if not exists tweet_data (
created_at DATETIME,
user_name VARCHAR (20),
retweet_count INT,
favourite_count INT,
tweet_followers_count INT,
is_retweet BOOLEAN,
tweet_source VARCHAR(256),
user_location VARCHAR(256),
tweet_mentioned_count INT,
tweet_ID VARCHAR(256) NOT NULL,
tweet_text VARCHAR(140),
UNIQUE (tweet_ID) );
Man this code is running perfectly.
go to this link and check it your self
http://rextester.com/l/mysql_online_compiler

MySQL Create Table Error Syntax

Hello i am having an issue when trying to create a table inside of my database webhostc_MyRadContactForm
When i try to execute the statement below in phpMyAdmin i get this error
CREATE TABLE Contacts (
-> ContactID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> ContactName VARCHAR(100),
-> ContactEmail VARCHAR(100),
-> ContactLeastFavoriteColor VARCHAR(10)
-> ContactDateCreated DATETIME
-> );
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '-> ContactID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> ContactName VARCHA' at line 2
Also phpMyAdmin flags these lines:
My server is running: 10.0.22-MariaDB
You are missing a comma just after ContactLeastFavoriteColor VARCHAR(10) and those arrows, ->, are not supposed to be there. The following is the correct syntax for creating your table:
CREATE TABLE Contacts (
ContactID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
ContactName VARCHAR(100),
ContactEmail VARCHAR(100),
ContactLeastFavoriteColor VARCHAR(10),
ContactDateCreated DATETIME
);
Good luck!!
There are two problems:
Those -> symbols aren't part of SQL syntax. They're the prompts that the MySQL monitor prints when you enter a multi-line query. You can't copy them into PhpMyAdmin.
You're missing a comma at the end of the ContactLeastFavoriteColor line.

Error 1064 Syntax Error MySQL Table Creation

Creating a table in MySQL results in error 1064. I do not have restricted words for table name.
mysql> create database NamesInc
-> ;
Query OK, 1 row affected (0.10 sec)
mysql> create table NameInfo(
-> Name_ID NUMBER(8),
-> Language VARCHAR2(10),
-> Status VARCHAR2(10),
-> Standard VARCHAR2(10),
-> Place_ID Number(8) NOT NULL,
-> Supplier_ID NUMBER(8) NOT NULL,
-> Date Supplied DATE,
-> PRIMARY KEY (Name_ID),
-> );
Error 1064 (42000): 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 'NUMBER(8),
Language VARCHAR2(8),
Status VARCHAR2(10),
PL' at line 2
Please let me know if I can provide additional information.
After create db statement do:
USE NamesInc;
create table NameInfo(
Name_ID INT(8),
Language VARCHAR(10),
Status VARCHAR(10),
Standard VARCHAR(10),
Place_ID INT(8) NOT NULL,
Supplier_ID INT(8) NOT NULL,
Date_Supplied DATE,
PRIMARY KEY (Name_ID)
);