Why is my Update statement not working? - mysql

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;

Related

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 TO CREATE TABLE IN 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,

MYSQL Table Error - 1064

Trying to create the following table:
CREATE TABLE login (
IdUser int(11) NOT NULL AUTO_INCREMENT,
username varchar(45) CHARACTER SET latin1 NOT NULL,
pass varchar(45) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (IdUser),
ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$);
Doesn't seem to work properly. The error I'm getting in MYSQL is:
#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 '=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$' at line 6
Bracket in the wrong spot:
PRIMARY KEY (IdUser),
ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8$$);
^----
should be
PRIMARY KEY (IdUser) <--note removed comma
) ENGINE=MyIsam etc...
^---
You're treating those table options as they were fields, by placing them WITHIN the () field definition block.
In my case some of the sql is working but mostly not working after changing Type=ENGINE.
CREATE TABLE `p4_acl_page` (
`id` int(2) NOT NULL auto_increment,
`label` varchar(80) default NULL,
`lastupdate` timestamp(14) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyIsam;

Problems export/importing between MySQL versions

I'm attempting to import an SQL file generated by 5.5.25-MariaDB-mariadb1 into 5.1.55-rel12.6 - (Percona Server (GPL), 12.6 , Revision 200) after importing the first 11 tables the import process breaks with the following error:-
ERROR 1064 (42000) at line 35252: 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 'PAGE_CHECKSUM=1' at line 10
Line 35252 contains the following:-
CREATE TABLE `kygvj_bwps_lockouts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`type` int(1) NOT NULL,
`active` int(1) NOT NULL,
`starttime` int(10) NOT NULL,
`exptime` int(10) NOT NULL,
`host` varchar(20) DEFAULT NULL,
`user` bigint(20) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=Aria AUTO_INCREMENT=3 DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1;
Can anyone suggest what the right syntax might be? I have been unable to locate the documentation referred to in the error message.

Insert query in mysql with an auto_increment field

Ok,
I am sure I am doing something wrong here but I can't for the life of me figure it out.
Here is my table
CREATE TABLE `email_queue` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`from` varchar(256) DEFAULT NULL,
`to` varchar(4182) DEFAULT NULL,
`cc` varchar(4182) DEFAULT NULL,
`subject` varchar(4182) DEFAULT NULL,
`body` varchar(4182) DEFAULT NULL,
`status` varchar(64) DEFAULT NULL,
`attempts` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`)
)
When I do a
insert into email_queue values (1,'','','','','','',0);
it works fine and inserts the blank values
but when I try to insert partial values using
insert into email_queue(to) values('sample_to_name');
it errors out saying
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 'to) v
alues('sample_to_name')' at line 1
What am I doing wrong?
to is mysql reserved word should be in backticks.
Either avoid the creating column names with Reserved words or enclose them with backtick ``
insert into email_queue(`to`) values('sample_to_name');
You need back-ticks around to
insert into email_queue(`to`) values('sample_to_name');
problem is because
to is mysql reserved word