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

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

Related

error while importing an sqlto phpMyAdmin db

I want to import an SQL file to my phpMyAdmin database, the file contains tables about a restaurant application and a table about the admin login, but I have 2 unexpected errors, I really don't see what is exactly wrong with that?. here is the error message:
Static analysis:
2 errors were found during analysis.
An opening bracket followed by a set of values was expected. (near "CREATE" at position 285)
Unexpected token. (near "CREATE" at position 285)
SQL query:
-- -- Déchargement des données de la table `operation` --
INSERT INTO `operation` (`numop`, `numcp`, `prenom`, `nom`, `type`, `numcp2`, `mentant`, `date`) VALUES
-- -------------------------------------------------------- --
-- Structure de la table `reclamation` --
CREATE TABLE `reclamation` (
`numrec` int(11) NOT NULL
,`id` varchar(8) NOT NULL
,`prenom` varchar(30) NOT NULL
,`nom` varchar(30) NOT NULL
,`text` text NOT NULL
,`date` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;
MySQL said: Documentation
#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 'CREATE TABLE `reclamation` (
`numrec` int(11) NOT NULL,
`id` varchar(8) NO' at line 14
CREATE TABLE `reclamation` (
`numrec` int(11) NOT NULL,
`id` varchar(8) NOT NULL,
`prenom` varchar(30) NOT NULL,
`nom` varchar(30) NOT NULL,
`text` text NOT NULL,
`date` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
There are no values after VALUES in operation insertion query.
This error points on create because this is the next to the insertion and it expected to be values but actually is CREATE ...
It seems the values cutted off, make sure to separate between queries with ;
INSERT INTO `operation` (`numop`, `numcp`, `prenom`, `nom`, `type`, `numcp2`, `mentant`, `date`) VALUES
-- Structure de la table reclamation --
CREATE TABLE `reclamation` (
`numrec` int(11) NOT NULL
,`id` varchar(8) NOT NULL
,`prenom` varchar(30) NOT NULL
,`nom` varchar(30) NOT NULL
,`text` text NOT NULL
,`date` datetime NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ;

Change TIMESTAMP when execute update query

I try to update some values with an update query but have problems to create this table on reg_update:
CREATE TABLE Product (
id INT(3) PRIMARY KEY,
product VARCHAR(20) NOT NULL,
reg_date TIMESTAMP,
reg_update NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
I get this error:
ERROR 1064 (42000): 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 DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)' at line 5
Is it posible to update in this case reg_update ?
try this
CREATE TABLE Product (
id INT(3) PRIMARY KEY,
product VARCHAR(20) NOT NULL,
reg_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
reg_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

making a Mysql table and I keep getting the same syntax error

Im very new to mysql and I keep getting the same error whenever i try to make a table
CREATE TABLE tasks {
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT PRIMARY KEY ,
description VARCHAR(64) NOT NULL,
completed TINYINT(2) NOT NULL DEFAULT 0,
created DATETIME NOT NULL DEFAULT NOW(),
last_updated DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW()
};
I wanted it to make a table but instead I got:
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 '{
id INT NOT NULL PRIMA' at line 1
You have a syntax error. CREATE TABLE uses parentheses not braces.
CREATE TABLE foo(col1 int, col2 varchar(25), col3 timestamp);
Here is the right syntax:
CREATE TABLE tasks (id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, description VARCHAR(64) NOT NULL, completed TINYINT(2) NOT NULL DEFAULT 0, created DATETIME NOT NULL DEFAULT NOW(), last_updated DATETIME NOT NULL DEFAULT NOW() ON UPDATE NOW())

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.

Why this query throwing error while inserting record

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');