Why this query throwing error while inserting record - mysql

i have created one table using following query
CREATE TABLE `events` (
`event_id` bigint(20) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`event_name` varchar(100) NOT NULL,
`description` text,
`event_date` datetime NOT NULL,
`repeat` tinyint(4) NOT NULL,
`share` varchar(100) DEFAULT NULL,
`share_type` varchar(50) NOT NULL,
PRIMARY KEY (`event_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
and now i am trying to insert record using this query
INSERT INTO events (username,event_name,description,event_date,repeat,share,share_type) VALUES ('bhavik','Will go home','','2012-11-11 18:10','0','','public');
error i am getting
#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 'username,event_name,description,event_date,repeat,share,share_type) VALUES ('bha' at line 1

repeat is a reserved keyword
use `repeat` in the insert statement
INSERT INTO events (username,event_name,description,event_date,`repeat`,share,share_type) VALUES ('bhavik','Will go home','','2012-11-11 18:10','0','','public');

Related

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB

CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double(11) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
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 ') NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT
CHARSET=latin1 AUTO_INCRE' at line 5
try using float without the number of showing digit
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` double NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
and for price could be you need a fixed decimal length so you should use decimal
CREATE TABLE IF NOT EXISTS `tbl_product` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`image` varchar(255) NOT NULL,
`price` decimal(10,2) NOT NULL,
PRIMARY KEY (id))
ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
You're missing a value in your double specifier:
`price` double(11) NOT NULL
It needs both the total digits and the digits following the decimal. Something like:
`price` double(11,2) NOT NULL
Though for currency values you may be better off using decimal instead:
`price` decimal(11,2) NOT NULL
As this uses a more fixed precision. Using a double may result in unexpected calculation results from how floating point arithmetic works.

#1064 - You have an error in your SQL syntax; Timestamp table

I've searched the page for answers, however, I am not able to solve this.
I receive 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 '' at line 5
When I am pasting this in the database:
CREATE TABLE IF NOT EXISTS `Votes_History` (
ID int(11) NOT NULL AUTO_INCREMENT,
Username varchar(100) NOT NULL,
Coin varchar(30) NOT NULL,
Timestamp int(11) NOT NULL,
PRIMARY KEY (ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6;
This is what I used to enter data into the Votes_History table:
INSERT INTO `Votes_History` (`ID`, `Username`, `Coin`, `Timestamp`)
VALUES
What am I doing wrong here?
Robin
If the query you are using is the same as the one in this sqlfiddle : http://sqlfiddle.com/#!9/01dcb/1 then you query is valid
What I remarked is you are declaring Timestamp as int(11), if you give to your INSERT statement Timestamp value as NOW() or DATE() then its a syntax error.
For TIMESTAMP type example:
# This table used TIMESTAMP type
CREATE TABLE IF NOT EXISTS `Votes_History_Timestamp` (
ID int(11) NOT NULL AUTO_INCREMENT,
Username varchar(100) NOT NULL,
Coin varchar(30) NOT NULL,
Timestamp TIMESTAMP NOT NULL,
PRIMARY KEY (ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=6;
INSERT INTO `Votes_History_Timestamp` (`Username`, `Coin`, `Timestamp`)
VALUES ('Hamza', '50MAD', NOW());
SQLFiddle link for timestamp : http://sqlfiddle.com/#!9/7878c9/1

Mysql i get Error when i try to edit after insert data

this is my one of database table structure and after insert some fields as row into that i can't update columns and i get error:
CREATE TABLE `channels` (
`id` int(11) NOT NULL,
`channelName` varchar(30) COLLATE utf8_persian_ci NOT NULL,
`channelLink` varchar(50) COLLATE utf8_persian_ci NOT NULL,
`channelDescription` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelImageFileName` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelAvatarFileName` varchar(100) COLLATE utf8_persian_ci NOT NULL,
`channelState` tinyint(1) NOT NULL,
`channelType` enum('channels','userCreatedChannels') COLLATE utf8_persian_ci NOT NULL,
`channelOwnerUserId` int(11) NOT NULL,
`fileServerUrlId` int(11) NOT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_persian_ci;
--
-- Indexes for dumped tables
--
--
-- Indexes for table `channels`
--
ALTER TABLE `channels`
ADD PRIMARY KEY (`id`);
Error and notice:
This table does not contain a unique column. Features related to the grid edit, checkbox, Edit, Copy and Delete links may not work after saving.
Error
UPDATE `channels` SET `channelState` = '1' WHERE LIMIT 1
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 'LIMIT 1' at line 1
id of this table is unique and A_I, how can i resolve this problem?

I keep getting an error when trying to make a table in phpmyadmin

when I was trying to run this code:
USE user;
CREATE TABLE IF NOT EXISTS 'posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'date_added' date NOT NULL,
'added_by' varchar(255) NOT NULL,
'user_posted_to' varchar(255) NOT NULL,
PRIMARY KEY ('id')
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
It gave me 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 ''posts' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'body' text NOT NULL,
'dat' at line 1
how do I solve it? By the way, I already selected a database? Any help would be appreciated.
Get rid of all the "'" marks.
CREATE TABLE IF NOT EXISTS posts (
id int(11) NOT NULL AUTO_INCREMENT,
body text NOT NULL,
date_added date NOT NULL,
added_by varchar(255) NOT NULL,
user_posted_to varchar(255) NOT NULL,
PRIMARY KEY (id)
)ENGINE=MYISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=10;
Here is a fiddle with a working creation.

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