This question already has answers here:
When to use single quotes, double quotes, and backticks in MySQL
(13 answers)
Closed 9 years ago.
Please help me!
I imported a MySQL file with this code:
delimiter $$
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$$
CREATE TABLE "photos" (
"IdPhoto" int(11) NOT NULL AUTO_INCREMENT,
"title" varchar(100) CHARACTER SET latin1 NOT NULL,
"IdUser" int(11) NOT NULL,
PRIMARY KEY ("IdPhoto")
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8$$
....and I get the following error:
MySQL said:
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 'delimiter $$ CREATE TABLE "login" (
"IdUser" int(11) NOT NULL AUTO_INCREME' at line 1
Update:
Problem solved. Thank you for responding!
CREATE TABLE `login` (
`IdUser` int(11) NOT NULL auto_increment,
`username` varchar(45) NOT NULL,
`pass` varchar(45) NOT NULL,
PRIMARY KEY (`IdUser`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
CREATE TABLE `photos` (
`IdPhoto` int(11) NOT NULL auto_increment,
`title` varchar(100) NOT NULL,
`IdUser` int(11) NOT NULL,
PRIMARY KEY (`IdPhoto`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
The delimiter command is not a server instruction; rather, it is a client-specific instruction recognised by certain client programmes such as the MySQL command line tool. It has the effect of changing the character that the client programme recognises as delimiting the statements which are to be sent to the server.
In phpMyAdmin, the statement delimiter can be changed in the Delimiter text box before clicking Go.
Related
Continuation from this question:
PDO query updating a datetime column not in query
A column in my table called lastLoginDate was being automatically updated even though my prepared statement did not include said column.
Apparently, when I created the new column, a trigger was set.
Upon using the command SHOW CREATE TABLE table_name, I returned the following results:
CREATE TABLE `users_edi` (
`username` varchar(30) NOT NULL DEFAULT '',
`fullname` varchar(50) DEFAULT NULL,
`userlevel` tinyint(1) unsigned NOT NULL,
`ipaddress` varchar(30) DEFAULT NULL,
`email` varchar(150) DEFAULT NULL,
`entrydate` datetime DEFAULT NULL,
`division` varchar(35) DEFAULT NULL,
`password` varchar(32) DEFAULT NULL,
`userid` varchar(32) DEFAULT NULL,
`timestamp` int(11) unsigned NOT NULL,
`job_title` varchar(30) DEFAULT NULL,
`dept` varchar(50) DEFAULT NULL,
`phone` varchar(11) DEFAULT NULL,
`lastLoginDate` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, // <-- here
PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
The table is years old. I just created the column and somehow, a trigger was set to it (I guess).
Regardless, I tried to remove it using the following command:
ALTER TABLE `users_edi`
`lastLoginDate` datetime DEFAULT NULL
But I only get the following error:
[Err] 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 '`lastLoginDate` datetime DEFAULT NULL' at line 4
How do I remove this trigger using the ALTER TABLE command or any other command?
ALTER TABLE users_edi MODIFY COLUMN lastLoginDate DATETIME DEFAULT NULL;
You might like to read this page on ALTER TABLE: https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
For a wordpress website I am trying to migrate the website and MySQL database. Although when I import it, it gives me an error. I no longer have access to the old one.
Error
SQL query:
CREATE TABLE `wp_commentmeta` (
`meta_id` bigint(20) UNSIGNED NOT NULL,
`comment_id` bigint(20) UNSIGNED NOT NULL DEFAULT '0',
`meta_key` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
`meta_value` longtext COLLATE utf8mb4_unicode_520_ci
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci
MySQL said: Documentation
#1046 - No database selected
1046 - No database selected Should have been a bit of a clue. Add a USE DATABASE_NAME; at the top of this script. So that MYSQL knows which database you are trying to create the table in
– RiggsFolly
I have the following SQL query
CREATE TABLE IF NOT EXISTS `Log` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`customer_id` int(11) unsigned NOT NULL,
`request_xml` BLOB NOT NULL,
`response_xml` LONGBLOB NOT NULL,
`timestamp_process_end` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`timestamp_response` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
);
could someone see any mistakes? Because it gives me a SQL Error when I run the code on server. But on localhost works without any problems (or phpmyadmin)
And btw this works on the server:
CREATE TABLE IF NOT EXISTS `lang` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`language` varchar(2) COLLATE utf8_unicode_ci NOT NULL UNIQUE,
PRIMARY KEY (`id`)
);
that is written in the same style. Any remarks?
LE: Mysql Ver 14.14 Distrib 5.1.73
In the end, the problem was that on the remote server I couldn't have two DEFAULT CURRENT_TIMESTAMP, as stated here mysql link, but this is wired that on the localhost worked.
I am getting the following error message when trying to run some sql code in my 5.5.35-MariaDB. Please can someone help me understand what is wrong?
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 'CREATE TABLE IF NOT EXISTS action_recorder ( id int(11) NOT NULL AUTO_I' at line 1
My code is below:
CREATE TABLE IF NOT EXISTS `action_recorder` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`module` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`user_id` int(11) DEFAULT NULL,
`user_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`identifier` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`success` char(1) COLLATE utf8_unicode_ci DEFAULT NULL,
`date_added` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `idx_action_recorder_module` (`module`),
KEY `idx_action_recorder_user_id` (`user_id`),
KEY `idx_action_recorder_identifier` (`identifier`),
KEY `idx_action_recorder_date_added` (`date_added`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=23 ;
Please can someone help me resolve this? Thanks!
You're missing the closing parenthesis. The one at the end is only for the key idx_action_recorder_date_added, but you need another one to close the whole table definition.
Also, I think you shouldn't use those normal single quotes. They are for strings. Use backticks or omit them altogether.
Since the "near..." mentions 'CREATE...', the error is either the CREATE or what immediately precedes it. I vote for the latter -- Look at what have right before it.
This is the query I have used for creating the table
CREATE TABLE IF NOT EXISTS `logging_api_request_js` (
`id` int(30) unsigned NOT NULL AUTO_INCREMENT,
`log_message` longtext,
`level` varchar(10) DEFAULT NULL,
`ip_address_merchant` varchar(45) DEFAULT NULL,
`ip_address_customer` varchar(45) DEFAULT NULL,
`creationTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updateTime` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11
It showed an error Incorrect table definition; there can be only one TIMESTAMP column with CURRENT_TIMESTAMP in DEFAULT or ON UPDATE clause
When I googled I saw that in the mysql 5.6. version this issue / restriction has been took off.But i wont be able to upgrade mysql right now.
Is there any work around for this,whith out changing the table structure to dump this using mysql?Please help.Im having little knowledge about the db operations.Do help.Thanks
You could remove ON UPDATE CURRENT_TIMESTAMP and create trigger.
DROP TRIGGER IF EXISTS `update_logging_api_request_js`;
DELIMITER //
CREATE TRIGGER `update_logging_api_request_js` BEFORE UPDATE ON `logging_api_request_js`
FOR EACH ROW BEGIN
SET NEW.updateTime = NEW.creationTime;
END
//
DELIMITER ;