ERROR TO CREATE TABLE IN MYSQL - mysql

I'm trying to create this table in SQL,
CREATE TABLE `online_status` (
`fk_user_id` int(10) unsigned NOT NULL default '0',
`last_activity` timestamp(14) NOT NULL,
PRIMARY KEY (`fk_user_id`)
) ENGINE=MyISAM;
but is returning 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 '(14) NOT NULL,
PRIMARY KEY (fk_user_id)
) ENGINE=MyISAM' at line 3
I've changed the commas, but the error continues. Can you help me on what is wrong?

`last_activity` timestamp(14) NOT NULL,
should be
`last_activity` timestamp NOT NULL,

Related

MySQL version 8 still has a problem with default values on TIMESTAMP /DATETIME?

Running MySQL locally on my Mac:
Server version: 8.0.29 Homebrew
Mysql says:
ERROR 1064 (42000) at line 16: 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 ', `created_at` TIMESTAMP
NOT NULL DEFAULT CURRENT_TIMESTAMP,
Okay, but I've looked at this a long time and I do not see what the mistake is:
CREATE TABLE IF NOT EXISTS `core_mvp`.`users` (
`id` BINARY(16) NOT NULL DEFAULT (UUID_TO_BIN(UUID()),
`created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`ip_address` VARCHAR(45) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
UNIQUE INDEX `ip_address_UNIQUE` (`ip_address` ASC) VISIBLE)
ENGINE = InnoDB;
I initially thought this error was about the TIMESTAMP or the DATETIME but I've tried every variation, including going with a static "0000-00-00 00-00-00" and I still get the error, so now I think the problem is elsewhere. Does anyone see a problem with this?
There is the also the declaration of the id as UUID, but I'm following all of the advice from here:
UUID as default for MySQL id column
If I remove the default for the DATETIME:
CREATE TABLE IF NOT EXISTS `core_mvp`.`users` (
`id` BINARY(16) NOT NULL DEFAULT (UUID_TO_BIN(UUID()),
`created_at` DATETIME NOT NULL ,
`ip_address` VARCHAR(45) NOT NULL COMMENT 'Bill wants us to have a concept of Guest',
PRIMARY KEY (`id`),
UNIQUE INDEX `id_UNIQUE` (`id` ASC) VISIBLE,
UNIQUE INDEX `ip_address_UNIQUE` (`ip_address` ASC) VISIBLE)
ENGINE = InnoDB;
I still get:
ERROR 1064 (42000) at line 16: 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 ',
`created_at` DATETIME NOT NULL ,
`ip_address` VARCHAR(45) NOT NULL COMMENT' at line 2
So I guess this has nothing to do with the default values. It is something else.

Got a syntax error after an attempt to create tables in MySQL but all should be correct I think

I think that the syntax is correct, but when I am trying to create that tables I get syntax errors:
CREATE TABLE `authors` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL
) DEFAULT CHARSET=latin1;
CREATE TABLE `categories` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`img` TEXT NOT NULL
) DEFAULT CHARSET=latin1;
CREATE TABLE `reviews` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`customer_id` INT(10) NOT NULL,
`product_id` INT(10) NOT NULL,
`grade` ENUM('Wspaniała', 'Dobra', 'Taka sobie', 'Zła', 'Bardzo zła') NOT NULL,
`content` TEXT NOT NULL
) DEFAULT CHARSET=latin1;
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 'CREATE TABLE `authors` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMEN' at line 10
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 'CREATE TABLE `categories` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCREMENT,
' at line 10
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 '-
-
-
CREATE TABLE `reviews` (
`id` INT(10) NOT NULL PRIMARY KEY AUTO_INCRE' at line 1
Do You maybe know what I am doing wrong?
Thank You.
I have just got an idea to manually, table-by-table, create authors, categories, and reviews. The only things I got as bad results were warnings about INT(10) being deprecated.

MySQL 5.6.13 not executing create table properly

I have the following SQL to create a table on a MySQL 5.6.13 instance:
CREATE TABLE 'exchange' (
'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL,
'name' varchar(255) NOT NULL,
'city' varchar(255) NULL,
'country' varchar(255) NULL,
'currency' varchar(128) NULL,
'time_zone_offset' time NULL,
'created_date' datetime NOT NULL,
'last_updated_date' datetime NOT NULL,
PRIMARY KEY ('id')
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
However, I keep getting the following unhelpful 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
''exchange' ( 'id' int NOT NULL AUTO_INCREMENT,
'abbrev' varchar(32) NOT NULL, 'n' at line 1
I must be missing something glaringly obvious...
Any ideas where I'm going wrong?
Try :
CREATE TABLE exchange (
Ref:
http://dev.mysql.com/doc/refman/5.1/en/create-table.html
Remove all quotes, this helped me on a windows machine command line

Error 1064 <42000> on mysql when i'm trying to create table

CREATE TABLE `photos` (
`title` varchar(255) not null,
`id` int(11) not null,
`ph_path` varchar(255) not null,
`description` varchar(255) not null,
`privilange` varchar(20) not null,
`owner` varchar(60) not null,
`provoles` int(11),
PRIMARY KEY (`id`),
) ENGINE=InnoDB DEFAULT CHARSET=greek;
I'm getting error 1064 <4200> and I'm not sure what is wrong.
You have a trailing comma in the primary key:
PRIMARY KEY (`id`), <--- remove that
The full error would read something like:
check the manual that corresponds to your MySQL server version for the right syntax to use near ') ENGINE=InnoDB
In MySQL, the position pointed to by the error message (near ')ENGINE) will show you the character immediately after where the error occurred. Look to the previous thing in your statement and you'll find your syntax error.
You will have to remove the comma after PRIMARY KEY (`id`).

Why is my Update statement not working?

Using the following query, I can't figure out why my update is not working. I'm sure its something stupid, but any help is greatly appreciated:
UPDATE Mail
SET From="Spouse"
WHERE ItemNum=9;
The Error is:
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 'From="Spouse" WHERE ItemNum=9' at line 1
The schema of Mail is:
CREATE TABLE `Mail` (
`ItemNum` int(11) NOT NULL auto_increment,
`Qtr` int(11) NOT NULL default '0',
`MsgDate` date default NULL,
`From` varchar(64) default NULL,
`Message` varchar(255) default NULL,
PRIMARY KEY (`ItemNum`)
) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=latin1
From is a MySQL reserved keyword. Surround it with backticks:
UPDATE Mail
SET `From`="Spouse"
WHERE ItemNum=9;