Create MySQL Database with Xampp - mysql

I have the following query for creating a table in my database but I am getting an error:
CREATE TABLE student (
accountNumber INT NOT NULL PRIMARY KEY,
firstName CHAR(20),
lastName CHAR(20),
courseID VARCHAR(6),
grade DOUBLE(3)
)
The error I am getting is:
ERROR 1064 (42000): 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 '))' at line 1

You dont need NOT NULL if declaring a Primary Key...because that key always needs to be available

Related

MySQL giving me syntax error referring to characters that don't exist? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
DROP DATABASE IF EXISTS `company_db`;
CREATE DATABASE `company_db`;
USE `company_db`;
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL;
);
CREATE TABLE roles(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR (30) NOT NULL,
salary DECIMAL,
department_id INT;
);
CREATE TABLE employee(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
first_name VARCHAR (30) NOT NULL,
last_name VARCHAR (30) NOT NULL,
role_id INT NOT NULL,
manager_id INT;
);
Here's my code above. When I try to run this schema file I get the following errors.
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 '' at line 3
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 ')' at line 1
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 '' at line 5
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 ')' at line 1
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 '' at line 6
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 ')' at line 1
What are they talking about? There isn't even a ')' in line 1. Is there something I'm misunderstanding about this? Thanks in advance!
You have an abundance of ;. This terminates each statement, it should not be present within the create:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL
);
CREATE TABLE roles(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
title VARCHAR (30) NOT NULL,
salary DECIMAL,
department_id INT
);
CREATE TABLE employee(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
first_name VARCHAR (30) NOT NULL,
last_name VARCHAR (30) NOT NULL,
role_id INT NOT NULL,
manager_id INT
);
In each create statement, you have “;” after the last column… this is interpreted as the end of the SQL statement which is causing a syntax error. Just remove them.
The line numbers are within each statement, and you have extra semicolons. So your:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL;
);
is two statements. The first:
CREATE TABLE department(
id INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
department_name VARCHAR (30) NOT NULL
complains about a syntax error at '' on line 3 (the end, where it is expecting a , or ) and sees neither).
And the second:
);
complains about a syntax error at ')' on line 1 (for obvious reasons).

mysql error for a create table statement from shell client

Im trying to run the following from the mysql shell client:
MySQL localhost:33060+ ssl plaything SQL > CREATE TABLE areas (id SERIAL PRIMARY KEY, area_name VARCHAR);
and keep getting the following error:
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 ')' at line 1
where could I be going wrong?
solved by yoss:
try this: CREATE TABLE areas ( id int NOT NULL AUTO_INCREMENT, area_name varchar(255), PRIMARY KEY (id) );
varchar did not have number of characters specified in the original statement

mysql error referring to Null

$sql1= "CREATE TABLE bookapp(
id int NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
pnumber int(11),
emailID VARCHAR(50),
reg_date datetime()
PRIMARY KEY(id)
)";
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 ''', NULL)' at line 1
You can use the following to create the table:
CREATE TABLE bookapp(
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(30),
pnumber INT(11),
emailID VARCHAR(50),
reg_date DATETIME,
PRIMARY KEY(id)
);
Explanation:
( and ) on DATETIME is invalid. DATETIME doesn't need a length.
You have to seperate the column definitions with ,. You forgot this after column reg_date.
Hint (to your error message):
Your given CREATE TABLE throws another error message, that is different to yours:
Error Code: 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 ') PRIMARY KEY(id) )' at line 6

how to add identity column for a table using mysql server 5.6?

i am trying to create a table with an identity column. i used the below query.
using mysql server 5.6.
create table t1
{
id int identity(1,1) Primary key
name varchar2(10)
};
but it shows the below 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 to use near '{ id int identity(1,1) Primary key name
varchar2(10) }' at line 2
kindly help me with the syntax.
use () instead of {}
Here the sample
http://www.w3schools.com/php/php_mysql_create_table.asp
Your answer should be
CREATE TABLE t1
(
id INTEGER AUTO_INCREMENT PRIMARY KEY,
name VARCHAR2(10)
)
Refer from https://bytes.com/topic/mysql/answers/652076-how-create-identity-column-mysql

Use MySQL in command prompt, ERROR 1064 (42000) occur when creating table

I am using xampp.
After creating a database
CREATE DATABASE University + use University
I create table by typing
CREATE TABLE Student
(
SNo INT NOT NULL,
SName VARCHAR(16) NOT NULL,
SAge INT NOT NULL,
SDepartment ENUM('CS', 'EE', 'Math', 'Physics') NOT NULL,
PRIMARY KEY (SNo)
);
But a beep is resulted and
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 'use University
CREATE TABLE Student
(
SNo INT NOT NULL,
Sname VARCHAR(16) NOT NULL,
SAg'
at line 2
is shown in command prompt. But I don't know what the syntax error is in this case.
I think the + is giving you syntax error. Try getting rid of it to separate these into two statements
CREATE DATABASE University
USE University