What is wrong with my code for phpmyadmin? - mysql

I tried to make a database is phpmyadmin, but I keep 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 '0) NULL,
Datum Verkocht DATE NULL,
Personeel VARCHAR(30) NULL,
`Min' at line 9
That's for this code
CREATE TABLE `veilingen`.`Veilingen`(
`Nr` INT(3) NOT NULL,
`Artikel` VARCHAR(100) NULL,
`Datum Geveild` DATE NULL,
`Tel. Verkoper` INT(10) NULL,
`Datum Ingeleverd` DATE NULL,
`Kast`
SET
(0) NULL,
`Datum Verkocht` DATE NULL,
`Personeel` VARCHAR(30) NULL,
`Minimum` DECIMAL NULL,
`Koop Nu` DECIMAL(100) NULL,
`Geveild Voor` DECIMAL(100) NULL,
`Betaald` ENUM(0) NULL,
`Cadeaubon` DECIMAL(100) NULL,
`Versturen` VARCHAR(100) NULL,
`Opmerkingen` VARCHAR(100) NULL,
PRIMARY KEY(`Nr`(1))
) ENGINE = MyISAM;
Sorry for the mess, I can't get the code span to work.
Can somebody help me?

Following is the right syntax for create table in php, you can edit this code according to your table name,column name and it's datatype.
CREATE TABLE employee (
empId int(11) NOT NULL AUTO_INCREMENT,
empName varchar(255) NOT NULL,
empDept varchar(255) NOT NULL,
PRIMARY KEY (empId)
)

Related

Mysql syntax Error when creating a table #1064

When I create a table in my localhost and it says
#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 'NOT NULL,
register_date DATETIME NOT NULL,
last_login DATETIME NOT NUL' at line 6"
(WampServer v 3.0.6 64bit, Apache 2.4.23 - MySql 5.7.14)
I've already try to change DB engine into InnoDB but the error was still appear.
Here is my Query
CREATE TABLE `inventry`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`username` VARCHAR(225) NOT NULL,
`email` VARCHAR(225) NOT NULL,
`password` VARCHAR(300) NOT NULL,
`usertype` ENUM(0) NOT NULL,
`register_date` DATETIME NOT NULL,
`last_login` DATETIME NOT NULL,
`notes` VARCHAR(225) NOT NULL,
PRIMARY KEY(`id`)
) ENGINE = InnoDB;
U P D A T E D******
I want store data in this field. but when i save this it getting error. How can i fix this.?
Try below -
CREATE TABLE users(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(225) NOT NULL,
email VARCHAR(225) NOT NULL,
password VARCHAR(300) NOT NULL,
usertype ENUM('0') NOT NULL,
register_date DATETIME NOT NULL,
last_login DATETIME NOT NULL,
notes VARCHAR(225) NOT NULL,
primary key (id)
)
just put, ENUM values, in quotes
CREATE TABLEinventry.users(
id INT NOT NULL AUTO_INCREMENT,
username VARCHAR(225) NOT NULL,
email VARCHAR(225) NOT NULL,
password VARCHAR(300) NOT NULL,
usertype ENUM(**'0'**) NOT NULL,
register_dateDATETIME NOT NULL,
last_loginDATETIME NOT NULL,
notesVARCHAR(225) NOT NULL,
PRIMARY KEY(id)
) ENGINE = InnoDB;

have an error when creating a table in phpmyadmin mysql

i need to create a table and this the SQL queries
CREATE TABLE person {
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
clth_color varchar(256) not null,
per_photo varchar(256) not null,
age varchar(10) not null,
description text not null,
loaction varchar(256) not null,
type int(1) not null,
user_id int(10) not null,
primary key(per_id),
foreign key(user_id) references users(user_id)
};
but i get 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 '{
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
' at line 1
Try using () instead {}
CREATE TABLE person (
per_id int(10) not null AUTO_INCREMENT,
name varchar(256) not null,
clth_color varchar(256) not null,
per_photo varchar(256) not null,
age varchar(10) not null,
description text not null,
loaction varchar(256) not null,
type int(1) not null,
user_id int(10) not null,
primary key(per_id),
foreign key(user_id) references users(user_id)
);
I'm not entirely sure but it might work.

Im getting an error when creating my database (#1064)

I was trying to create a database using phpmyadmin but I keep on getting 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 ') NOT NULL,First Name VARCHAR(30) NOT NULL,Last Name VARCHAR(30) NOT' at line 3
Im using Tomcat version 8.0. Below is the query I am Executing
CREATE TABLE `cs485_lab5`.`Orders` (
`Item Number` VARCHAR(20) NOT NULL,
`Price` DOUBLE(10) NOT NULL,
`First Name` VARCHAR(30) NOT NULL,
`Last Name` VARCHAR(30) NOT NULL,
`Shipping Address` VARCHAR(50) NOT NULL,
`Credit Card` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`Credit Card`)
) ENGINE = InnoDB;
Don't specify a length for DOUBLE. Also, if you are designing the table, don't put spaces in the column names. Use names that don't need escaping. Having to use escape characters just clutters up queries unnecessarily.
So:
CREATE TABLE Orders (
`ItemNumber` VARCHAR(20) NOT NULL,
`Price` DOUBLE NOT NULL,
`FirstName` VARCHAR(30) NOT NULL,
`LastName` VARCHAR(30) NOT NULL,
`ShippingAddress` VARCHAR(50) NOT NULL,
`CreditCard` VARCHAR(20) NOT NULL,
`CCN` INT(16) NOT NULL,
PRIMARY KEY (`CreditCard`)
) ENGINE = InnoDB;
Here is a SQL Fiddle.

Error trying to create table in MySQL via terminal

I am trying to create a table in my database via terminal.
Here is my syntax:
CREATE TABLE `users` (
PRIMARY KEY(id) NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHAR NOT NULL,
`gender` VARCHAR NOT NULL,
`fav_color` VARCHAR NOT NULL,
`birthdate` DATE NOT NULL
);
I am getting 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 to use near 'NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR NOT NULL,
`first_name` VARCHA' at line 2
What am i dong wrong here?
Besides the issues that Jens and Marc pointed out, You have to declare the length of your Varchar fields in order for this statement to work, like so:
CREATE TABLE `test`.`users` (
`id` INT NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(45) NOT NULL,
`first_name` VARCHAR(45) NOT NULL,
`gender` VARCHAR(45) NOT NULL,
`fav_color` VARCHAR(45) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY (`id`));
the syntax of your create statement is wrong:
the correct one is this:
CREATE TABLE `users` (
`id` int NOT NULL AUTO_INCREMENT,
`last_name` VARCHAR(255) NOT NULL,
`first_name` VARCHAR(255) NOT NULL,
`gender` VARCHAR(255) NOT NULL,
`fav_color` VARCHAR(255) NOT NULL,
`birthdate` DATE NOT NULL,
PRIMARY KEY(`id`)
);
For more Information see the offical documentation.
it should be
id int primary key auto_increment not null
You're trying to define a primary key on a field that doesn't exist. Keys cannot be "not null" and definitely cannot be "auto_increment".

#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 ')'

This is the code. However I kept getting this 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 7
Weirdly line 7 is the CREATE TABLE academicnews( line. Which does not contain ')' .
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL,
); #Line 7
Get rid of the last comma. It is unnecessary and invalid.
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL, <-- HERE
);
It should be
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL
);
You are getting this error bcoz of an addition comma.
CREATE TABLE academicnews(
anewsID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
title VARCHAR(50) NOT NULL,
anewsContent TEXT NOT NULL,
imagePath VARCHAR(200) NOT NULL,
timeNews DATE NOT NULL, <--- This is the error
);
CREATE TABLE IF NOT EXISTS `testinfo` (
`id` int(8) NOT NULL AUTO_INCREMENT,
`sl_no` int(10) NOT NULL,
`p1` int(3) DEFAULT NULL,
`p2` int(3) DEFAULT NULL,
`p3` int(3)DEFAULT select [p1]+[p2],
`mid` int(8) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `mid` (`mid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;