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.
Related
Good Day!
what is the proper syntax query in MySQL? I'm getting error in mysql during execution (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 'EmpCode AS CONCAT('EMP' , RIGHT(Concat('0000', CONVERT(EmpId, ' at line 3)
CREATE TABLE tbEmployee
(
EmpId INT NOT NULL, PRIMARY KEY,
EmpCode AS CONCAT('EMP' , RIGHT(Concat('0000', CONVERT(EmpId, CHAR(5))),5)) PERSISTED,
EmployeeName VARCHAR(50),
Age INT,
Gender VARCHAR(10)
)
MySQL generated columns are either VIRTUAL (the default) or STORED, the latter corresponding to SQL Server's persisted. Try this version:
CREATE TABLE tbEmployee (
EmpId INT NOT NULL PRIMARY KEY,
EmpCode VARCHAR(50) AS (CONCAT('EMP', LPAD(EmpId, 5, '0'))) STORED,
EmployeeName VARCHAR(50),
Age INT,
Gender VARCHAR(10)
);
Note also that MySQL is a bit more lax with regards to casting numeric columns to text. Also, we can use MySQL's LPAD function to left pad the employee ID with zeroes, to a width of 5 digits.
I am trying to create a table, but it gives me this error:
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 touse near ' INT NOT NULL AUTO_INCREMENT
Here is my code:
CREATE TABLE bowling_scores (
PlayerID, INT NOT NULL AUTO_INCREMENT
, LName VARCHAR(100) NOT NULL
, FName VARCHAR(100) NOT NULL
, Game1 INT NULL
, Game2 INT NULL
, Game3 INT NULL
, Game4 INT NULL
, PRIMARY KEY (PlayerID)
);
Here's a tip about syntax error messages: the message tells you where the error is.
check the manual that corresponds to your MySQL server version for the right syntax to use near ' INT NOT NULL AUTO_INCREMENT
This is telling you that MySQL became confused because it wasn't expecting to see that text. This usually means you made a mistake at that point, or immediately before it.
This can help you narrow down your search in the SQL statement to the point where it went wrong.
The error message also tells you what to do: check the manual. You should help yourself become better at SQL by reading documentation and examples.
I've been using MySQL for nearly 20 years, but I still refer to the reference docs every day. In fact, it's because I am experienced with MySQL that I know this is the right thing to do.
All SQL statements have a reference page in the manual. Here's the page for CREATE TABLE: https://dev.mysql.com/doc/refman/5.7/en/create-table.html
The MySQL manual is large, so it's easy to think "I don't know where the right page is." Gradually you can learn how the manual is organized. Pay attention to the hierarchy of links on the left column. When in doubt, just use Google for phrases like "mysql create table syntax".
You should be able to answer simple syntax errors for yourself instead of posting to Stack Overflow. You'll get your answer more quickly!
This is an obvious error:
PlayerID, INT NOT NULL AUTO_INCREMENT
You have an extraneous comma. It should be:
PlayerID INT NOT NULL AUTO_INCREMENT
Stop putting commas on the next line of your SQL statements as well!
This should work. You had a comma after PlayerID
CREATE TABLE bowling_scores (
PlayerID INT NOT NULL AUTO_INCREMENT,
LName VARCHAR(100) NOT NULL,
FName VARCHAR(100) NOT NULL,
Game1 INT NULL,
Game2 INT NULL,
Game3 INT NULL,
Game4 INT NULL,
PRIMARY KEY (PlayerID)
);
You should be writing something like:
creat table Bowling_score(Playerid int, Firstname varchar(100), Lastname varchar(100), Game1 int, Game2 int, Game3 int);
I try to create a table in MySQL:
mysql> create table order ( ID varchar(30) not null,
-> Cname varchar(100) not null,
-> name varchar(30),
-> Type varchar(30),
-> primary key(ID, Cname));
but an error occured:
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 ( ID varchar(30) not null, Cname
varchar(100) not null, name varchar(30), ' at line 1
I have checked for thousand time and I still find no error here.
Can anyone help me?
Its is because of the table name order.
There is an order by reserved word. Change the table name and it will work fine.
If you want order as table name use back ticks around the table name. It will workfine
I create a physical model in powerdesigner
and then generate the code for mysql5, and now in
phpmyadmin Im getting an 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 'create table CARD
Do you see why this can be happening?
Im creating my tables like this:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN _BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
And the problem seems like is in this part: int not null auto_increment,
You're missing the semi-colon at the end of your create statement. This makes the first line of the create statement for the next table an error which is what that error message is trying to tell you.
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
);
The problem is the space after ISBN:
create table books
(
COD_BOOK int not null auto_increment,
TITLE_BOOK varchar(50),
ISBN_BOOK varchar(20),
CATEGORY_BOOK varchar(20),
primary key (COD_BOOK)
)
Here is a SQL Fiddle.
I try to create a table but I keep getting an SQL Error but I can't figure out why.
This is the error:
check the manual that corresponds to your MySQL server version for the
right syntax to use near '+491634170770 (Id INT NOT NULL PRIMARY KEY
AUTO_INCREMENT,Type VARCHAR(20),Conte' at line 1 ERROR 1064 (42000):
You have an error in your SQL syntax;
This is my statement:
CREATE TABLE +491234175789 (
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Type VARCHAR(20),
Content MEDIUMBLOB
);
I already tried to find a solution here, but my syntax seems to be correctly. I think its because of the name of the table. But using backticks like this ´+491234175789´ didn't work.
This is the backtick `:
CREATE TABLE `+491234175789` (
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Type VARCHAR(20),
Content MEDIUMBLOB
);
However, don't create a table name that requires backticks. It is just bad form and makes queries harder to read and write -- you are creating problems for the future. Call it something like:
CREATE TABLE t_491234175789 (
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
Type VARCHAR(20),
Content MEDIUMBLOB
);