MySQL error syntax - mysql

I'm sort of confused here, what is wrong with my syntax?
CREATE TABLE `users` (
`userId` int(7) NOT NULL AUTO_INCREMENT,
`firstName` varchar(30) NOT NULL,
`lastName` varchar(30) NOT NULL,
`gender` varchar(1) NOT NULL,
`birthday` datetime NOT NULL,
`city` varchar(20) NOT NULL,
`province` varchar(20) NOT NULL,
`postalCode` varchar(6) NOT NULL,
`country` varchar(20) NOT NULL,
`email` varchar(30) NOT NULL,
`password` varchar(32) NOT NULL,
`bio` text NOT NULL,
`active` int(1) NOT NULL DEFAULT(0),
PRIMARY KEY (`userId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
This was auto generated from an SQL export. It gives the following 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), PRIMARY KEY (userId) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCR' at line 14

Specifying the default value is wrong.There is no need of braces
Replace
`active` int(1) NOT NULL DEFAULT (0),
with
`active` int(1) NOT NULL DEFAULT 0,

Related

Mysql Query Error 1054 - Unknown column in the 'field list'

I'm learning MYSQL FULL JOIN queries using the Northwind database. This is my query,
SELECT customers.CompanyName, orders.OrderID
FROM customers
FULL JOIN orders ON customers.CustomerID=orders.CustomerID
ORDER BY customers.CompanyName;
Customers table schema,
CREATE TABLE `customers` (
`CustomerID` varchar(5) NOT NULL,
`CompanyName` varchar(40) NOT NULL,
`ContactName` varchar(30) DEFAULT NULL,
`ContactTitle` varchar(30) DEFAULT NULL,
`Address` varchar(60) DEFAULT NULL,
`City` varchar(15) DEFAULT NULL,
`Region` varchar(15) DEFAULT NULL,
`PostalCode` varchar(10) DEFAULT NULL,
`Country` varchar(15) DEFAULT NULL,
`Phone` varchar(24) DEFAULT NULL,
`Fax` varchar(24) DEFAULT NULL,
`Image` longblob,
`ImageThumbnail` longblob,
PRIMARY KEY (`CustomerID`),
KEY `City` (`City`),
KEY `CompanyName` (`CompanyName`),
KEY `PostalCode` (`PostalCode`),
KEY `Region` (`Region`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Orders table schema,
CREATE TABLE `orders` (
`OrderID` int(11) NOT NULL AUTO_INCREMENT,
`CustomerID` varchar(5) DEFAULT NULL,
`EmployeeID` int(11) DEFAULT NULL,
`OrderDate` datetime DEFAULT NULL,
`RequiredDate` datetime DEFAULT NULL,
`ShippedDate` datetime DEFAULT NULL,
`ShipVia` int(11) DEFAULT NULL,
`Freight` decimal(19,4) DEFAULT '0.0000',
`ShipName` varchar(40) DEFAULT NULL,
`ShipAddress` varchar(60) DEFAULT NULL,
`ShipCity` varchar(15) DEFAULT NULL,
`ShipRegion` varchar(15) DEFAULT NULL,
`ShipPostalCode` varchar(10) DEFAULT NULL,
`ShipCountry` varchar(15) DEFAULT NULL,
PRIMARY KEY (`OrderID`),
KEY `CustomerID` (`CustomerID`),
KEY `EmployeeID` (`EmployeeID`),
KEY `OrderDate` (`OrderDate`),
KEY `ShippedDate` (`ShippedDate`),
KEY `ShipPostalCode` (`ShipPostalCode`)
) ENGINE=MyISAM AUTO_INCREMENT=11078 DEFAULT CHARSET=utf8;
And this is MySQL server version 5.7.35 - MySQL Community Server (GPL)
I am getting #1054 - Unknown column 'customers.CompanyName' in 'field list'
Can someone point out what I am doing wrong?
mysql don`t support full join,but oracle support
you can use
select customers.CompanyName, orders.OrderID from customers,orders where customers.CustomerID=orders.CustomerID order by
customers.CompanyName;

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,

CREATE TABLE IF NOT EXISTS `doctordata` (
`Id` int unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(50) DEFAULT NULL,
`Address` varchar(300) DEFAULT NULL,
`Phone` varchar(45) DEFAULT NOT NULL,
`AltPhone` varchar(45) DEFAULT NULL,
`Email` varchar(50) DEFAULT NULL,
`RegDate` varchar(50) DEFAULT NULL,
`Pincode` varchar(45) DEFAULT NULL,
`HospitalName` varchar(100) DEFAULT NULL,
`Validate` varchar(45) DEFAULT NULL,
`Document` varchar(500) DEFAULT NULL,
`IsOnline` varchar(45) NOT NULL,
`DepId` varchar(45) NOT NULL,
`Password` varchar(50) NOT NULL,
PRIMARY KEY (`Id`)
UNIQUE KEY `Phone` (`Phone`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
The complete error message:
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,
`AltPhone` varchar(45) DEFAULT NULL,
`Email` varchar(50) DEFAULT N' at line 5
CREATE TABLE IF NOT EXISTS `doctordata` (
`Id` int unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(50) DEFAULT NULL,
`Address` varchar(300) DEFAULT NULL,
`Phone` varchar(45) NOT NULL,
`AltPhone` varchar(45) DEFAULT NULL,
`Email` varchar(50) DEFAULT NULL,
`RegDate` varchar(50) DEFAULT NULL,
`Pincode` varchar(45) DEFAULT NULL,
`HospitalName` varchar(100) DEFAULT NULL,
`Validate` varchar(45) DEFAULT NULL,
`Document` varchar(500) DEFAULT NULL,
`IsOnline` varchar(45) NOT NULL,
`DepId` varchar(45) NOT NULL,
`Password` varchar(50) NOT NULL,
PRIMARY KEY (`Id`),
UNIQUE KEY `Phone` (`Phone`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
You made several typos. "DEFAULT NOT NULL" should be only "NOT NULL". Also you missed "," after "PRIMARY KEY" line.

MYSQL: Why I am not able create table

I am trying copy schema from one MYSQL database to other MYSQL database. While doing so few tables giving problem as follows
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 '(6) DEFAULT NULL,
`is_superuser` tinyint(1) NOT NULL,
`username` varchar(30)' at line 4
Execution Time : 0 sec
Transfer Time : 0 sec
Total Time : 0 sec
MYSQL SCRIPT
DROP TABLE IF EXISTS `auth_user`;
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` DATETIME(6) DEFAULT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` DATETIME(6) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;
Change DATETIME TO TIMESTAMP:
like this:
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` TIMESTAMP NOT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` TIMESTAMP NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;
MySQL retrieves and displays DATETIME values in 'YYYY-MM-DD HH:MM:SS' format. The supported range is '1000-01-01 00:00:00' to '9999-12-31 23:59:59'.You don't need to specify the length for datetime datatypes
DROP TABLE IF EXISTS `auth_user`;
CREATE TABLE `auth_user` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`password` VARCHAR(128) NOT NULL,
`last_login` DATETIME DEFAULT NULL,
`is_superuser` TINYINT(1) NOT NULL,
`username` VARCHAR(30) NOT NULL,
`first_name` VARCHAR(30) NOT NULL,
`last_name` VARCHAR(30) NOT NULL,
`email` VARCHAR(254) NOT NULL,
`is_staff` TINYINT(1) NOT NULL,
`is_active` TINYINT(1) NOT NULL,
`date_joined` DATETIME NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=INNODB AUTO_INCREMENT=33 DEFAULT CHARSET=latin1;

Sql error syntaxes with phpmyadmin

Good day,
I have an issue using the phpmyadmin for my database, I'm in new in this and this is the mysql structure from previewmysql:
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM(0) NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15) NULL,
`marital_status` ENUM(0) NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM(0) NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM(0) NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
The error is:
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) NOT NULL , `email` VARCHAR(20) NOT NULL , `phone` INT(15) NULL , `marital_sta' at line 1
And also attached is my phpmyadmin table structure.
Will appreciate any help.
Try it.Hope errors goes boom.I just fixed your errors. But your table structure is not good enough. give time, then day by day you will also be expert on it.
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM('0','1') NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15),
`marital_status` ENUM('0','1') NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM('0','1') NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM('0','1') NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
Modify ENUM declaration as ENUM ('male', 'female') for gender column and others also as shown in your table. It will not accept ENUM(0).
ENUM(0) is wrong format , if you want that for gender roles then you can use :-
ENUM('Male', 'Female') i.e you can run this query :-
CREATE TABLE `mydb`.`attendant`
(
`id` INT NOT NULL auto_increment,
`first_name` VARCHAR(20) NOT NULL,
`names` VARCHAR(50) NOT NULL,
`gender` ENUM('Male', 'Female') NOT NULL,
`email` VARCHAR(20) NOT NULL,
`phone` INT(15) NULL,
`marital_status` ENUM('Single','Married','divorced') NOT NULL,
`added_date` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`membership` ENUM('no','yes') NOT NULL,
`address` VARCHAR(20) NOT NULL,
`suburb` ENUM('Cape Town','Woodstock') NOT NULL,
`partner_name` VARCHAR(25) NULL,
PRIMARY KEY (`id`),
UNIQUE `email_address` (`email`)
)
engine = innodb;
You have used ENUM data type in your table. And provided 0 as argument but
An enumeration value must be a quoted string literal
You can refer the mySql documentation for more information
http://dev.mysql.com/doc/refman/5.7/en/enum.html

mysql error 1064

Im trying to create a table with this code:
CREATE TABLE IF NOT EXISTS `entries` (
`id` int(10) NOT NULL auto_increment,
`atom_id` varchar(512) NOT NULL,
`title` varchar(256) NOT NULL,
`author` varchar(128) NOT NULL,
`link` varchar(512) NOT NULL,
`content` longtext NOT NULL,
`updated` varchar(25) NOT NULL,
`inserted` varchar(25) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `atom_id` (`atom_id`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE IF NOT EXISTS `topics` (
`id` int(10) NOT NULL auto_increment,
`status` varchar(32) NOT NULL,
`hub` varchar(512) NOT NULL,
`topic` varchar(512) NOT NULL,
`lease` varchar(25) NOT NULL,
`secret` varchar(256) NOT NULL,
`token` varchar(40) NOT NULL,
`date` varchar(25) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
but i got 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 ') ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1' at line 12
I can't figure what's going on, any advice?
Remove the comma after UNIQUE KEY 'atom_id' ('atom_id'), in line 11
UNIQUE KEY `atom_id` (`atom_id`),
^
Try losing the ","