Why is this not creating a table? - mysql

I'm trying to create a table on mysql 5.5 with the following:
CREATE TABLE `markets` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`title` varchar(255) DEFAULT NULL,
`created_at` datetime(6) NOT NULL,
`updated_at` datetime(6) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=utf8mb4;
But I get the error:
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) NOT NULL,
01 `updated_at` datetime(6) NOT NULL,
01 PRIMARY KEY (`id`)
01 ) ENGINE' at line 4
What am I doing wrong here?

instead of
`created_at` datetime(6) NOT NULL,
`updated_at` datetime(6) NOT NULL,
try
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,

Related

MySQL said: Documentation #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version

I'm trying to import a SQL file into the database but facing this error. Please help if anyone can solve this error.
SQL query:
CREATE TABLE IF NOT EXISTS `products` (
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
`details` json NOT NULL,
`expiration_date` date ,
`barcode` varchar(125) COLLATE utf8mb4_unicode_ci,
`name` varchar(125) COLLATE utf8mb4_unicode_ci NOT NULL,
`bundle_id` bigint(20) UNSIGNED NOT NULL,
`shelf_id` bigint(20) UNSIGNED DEFAULT NULL,
`delivery_request_id` bigint(20) UNSIGNED DEFAULT NULL,
`status` int(11) NOT NULL DEFAULT '0',
`quantity` int(11) NOT NULL DEFAULT '1',
`weight` int(10) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
KEY `products_bundle_id_foreign` (`bundle_id`),
KEY `products_shelf_id_foreign` (`shelf_id`),
KEY `products_delivery_request_id_foreign` (`delivery_request_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
MySQL said: Documentation
#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 'json NOT NULL,
`expiration_date` date ,
`barcode` varchar(125) COLLATE utf8m' at line 5

MySQL error 1064 on create table

I'm trying to create table with
CREATE TABLE `notes` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`title` varchar(45) NOT NULL,
`content` varchar(45) NOT NULL,
`createdAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
But I get a 1064 error and I can't see what is wrong

MySQL issue with altering column to add default

I have a table named Users with a column call created. Whenever a record is created I want to add the datetime.
Users Table:
CREATE TABLE `Users` (
`userId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fullName` varchar(50) DEFAULT NULL,
`firstName` varchar(25) NOT NULL DEFAULT '',
`lastName` varchar(25) NOT NULL DEFAULT '',
`address` varchar(50) NOT NULL DEFAULT '',
`city` varchar(25) DEFAULT NULL,
`state` char(2) DEFAULT NULL,
`zipCode` varchar(25) DEFAULT NULL,
`email` varchar(50) NOT NULL DEFAULT '',
`cellPhone` varchar(15) DEFAULT NULL,
`birthDate` date NOT NULL,
`creditCard` varchar(250) NOT NULL DEFAULT '',
`subscriptionStarted` date NOT NULL,
`subscriptionEnded` date NOT NULL,
`basicPlan` tinyint(1) DEFAULT NULL,
`standardPlan` tinyint(1) DEFAULT NULL,
`premiumPlan` tinyint(1) DEFAULT NULL,
`staff` tinyint(1) DEFAULT NULL,
`admin` tinyint(1) DEFAULT NULL,
`systemAdmin` tinyint(1) DEFAULT NULL,
`edited` datetime DEFAULT NULL,
`created` datetime DEFAULT NULL,
PRIMARY KEY (`userId`)
) ENGINE=InnoDB AUTO_INCREMENT=27 DEFAULT CHARSET=latin1;
now i added this extra query to make my created field get the current datetime when a new record is created.
ALTER TABLE Users
ALTER COLUMN created SET DEFAULT CURRENT_TIMESTAMP
The problem is that I get the following error when running the alter table query
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 'CURRENT_TIMESTAMP' at line 2
Your syntax is slightly off, I think you have to specify the column to change:
ALTER TABLE Users CHANGE created created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
See this sample SQL Fiddle for an example.

MySQL error syntax

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,

MYSQL script import error

I am getting an error when I try to import data through the command:
mysql -u root -p"root" cvdb < "cvdb.sql"
The error I am getting is:
ERROR 1064 (42000) at line 72: 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 '(14) NOT NULL,
Created datetime NOT NULL default ' 0000-00-00 00:00:00 ',
' at line 14
The code of my SQL file is:
DROP TABLE IF EXISTS `activity`;
CREATE TABLE `activity` (
`AllDay` enum('YES','NO') default 'NO',
`ActivityID` int(11) unsigned NOT NULL auto_increment,
`Type` int(11) NOT NULL default '0',
`Priority` int(11) NOT NULL default '0',
`Status` int(11) NOT NULL default '0',
`Title` varchar(255) default NULL,
`DueDate` datetime default NULL,
`CompletedDate` datetime default NULL,
`Details` text,
`Creator` int(11) NOT NULL default '0',
`Owner` int(11) default NULL,
`ModifiedBy` int(11) default NULL,
`Modified` timestamp(14) NOT NULL,
`Created` datetime NOT NULL default ' 0000-00-00 00:00:00 ',
`Start` datetime default NULL,
`End` datetime default NULL,
`AttachmentType` enum('NONE','FILE','LINK') NOT NULL default 'NONE',
`Location` varchar(25) default NULL,
`visibility` enum('PRIVATE','PUBLIC') NOT NULL default 'PRIVATE',
`Notes` varchar(255) default NULL,
PRIMARY KEY (`ActivityID`),
UNIQUE KEY `ActivityID` (`ActivityID`),
KEY `Type` (`Type`),
KEY `Priority` (`Priority`),
KEY `Status` (`Status`),
KEY `Creator` (`Creator`),
KEY `Owner` (`Owner`),
KEY `ModifiedBy` (`ModifiedBy`),
KEY `Location` (`Location`)
) ENGINE=InnoDB;
the error is here Modified timestamp(14) NOT NULL. you should remove (14) from timestamp.
your partial DDL,
`ModifiedBy` int(11) default NULL,
`Modified` timestamp NOT NULL,
`Created` datetime NOT NULL default '0000-00-00 00:00:00',
`Start` datetime default NULL,
From mysql doc
Incompatible change: In very old versions of MySQL (prior to 4.1), the
TIMESTAMP data type supported a display width, which was silenty
ignored beginning with MySQL 4.1. This is deprecated in MySQL 5.1, and
removed altogether in MySQL 5.5. These changes in behavior can lead to
two problem scenarios when trying to use TIMESTAMP(N) columns with a
MySQL 5.5 or later server:
...
You should try to handle potential issues of these types proactively
by updating with ALTER TABLE any TIMESTAMP(N) columns in your
databases so that they use TIMESTAMP instead, before performing any
upgrades.
So try to remove the (14)
in
Modified timestamp(14) NOT NULL
or as said in doc, try to make alter table statements on your timestamp columns before import.