MySQL syntax issue on database and table - mysql

What is wrong with my syntax?
I'm trying to update several databases in one shot:
update `db_name1`.`db_table` SET `cc_number_enc` = NULL
update `db_name2`.`db_table` SET `cc_number_enc` = NULL
update `db_name3`.`db_table` SET `cc_number_enc` = NULL
and I'm getting query syntax error in phpmyadmin
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 'cc_number_enc = NULL' at line 1
UPDATE
I've rewritten the same query simply by copying & pasting, and now getting the following:
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 'cc_number_enc = NULL' at line 1
Question, is it matter from which database I'm running the query from in phpmyadmin?

try puting semicolon after query. It can happen because of multiple reasons.
references http://www.inmotionhosting.com/support/website/database-troubleshooting/error-1064
MySQl Error #1064
MySQL Nested Queries with Joins

Looks like when copying, your backticks are changed to some other symbol, which looks like backtick, but actually, it is not.
Try again without quotes, or manually put backticks in place.

Related

mysql insert query is syntactically correct but showing errors [duplicate]

This question already has answers here:
#1064 -You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version
(6 answers)
Closed 1 year ago.
INSERT INTO AlbumSongs (albumId,songId,rank) VALUES ("a3092aee5d397fef823656c31cd131e0","DPEUD1tm1RWp",9)
I tried to execute this query in my mysql database.
but it shows 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 'rank) VALUES ("a3092aee5d397fef823656c31cd131e0","DPEUD1tm1RWp",9)' at line 1
my mysql server version ```Ver 8.0.23-0ubuntu0.20.04.1 for Linux on x86_64 ((Ubuntu))``
What is wrong with this query? how can I solve this?
rank is a function in MySQL, so the query engine is expecting to see something like:
RANK() OVER (PARTITION BY {column} ORDER BY {column})
If you really must use this name for the column, consider putting all of your column names in back ticks like so:
INSERT INTO `AlbumSongs` (`albumId`, `songId`, `rank`)
VALUES ('a3092aee5d397fef823656c31cd131e0', 'DPEUD1tm1RWp', 9);
Note: Table names can also be wrapped the same way, and the strings are single-quoted rather than double quoted.
Ideally all table and column names should be defined like this when writing queries.

MySQL vs MariaDB - ddl - setting default for time field

I've got table products, and want to add column with type time.
I've got statement as follows:
ALTER TABLE products ADD openTime1 TIME DEFAULT TIME(now());
it works on MariaDB, but it doesnt work on Mysql.
On mysql it produces Error -
[42000][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 '(now())' at line 1
Can someone tell me why? whats wrong here? I thought that this should be the same.
In MySQL the expression used in DEFAULT field attribute must be wrapped into the parenthesis:
ALTER TABLE products ADD openTime1 TIME DEFAULT (TIME(now()));
db<>fiddle here

Issue with MySQL Generated Columns

Hello I am trying to make a alter an exsisting table to add a Generated columns which is the count of all the rows in another table(It will be a like system so I am going to do all the matching and "WHERE" once I get this to work)
I am currently using this.
ALTER TABLE board ADD like_cnt INT GENERATED ALWAYS AS (COUNT(*) FROM likes) NOT NULL;
But it gives 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 'FROM likes) NOT NULL' at line 1
I am using WAMP and it has SQL version 5.7.24
Is this not possible or am I doing something wrong ?
There are limits in GENERATED COLUMNS notably 'Subqueries are not permitted'

Enter Image URL (http://...) in mysql table

I tried using this in mysql:
INSERT INTO users (url) VALUES (http://31.media.tumblr.com/tumblr_ljtc6i9GPA1qbq4v6o1_400.gif) WHERE id='15';
But it gives this error:
"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 '://31.media.tumblr.com/tumblr_ljtc6i9GPA1qbq4v6o1_400.gif) WHERE id='15'' at line 1"
Can anyone tell me what is the reason and how to store the url in the table?
INSERT INTO statements don't have a WHERE clause. If you are wanting to use a WHERE clause you are just UPDATEing a row.
UPDATE table_name
SET column1=value1,column2=value2,...
WHERE some_column=some_value;

unable to Drop a table in My Sql, You have an error in your SQL syntax 1064

i have just make a table as Customer 1,
& now want to Drop that, so used DROP TABLE Customer 1. but my sql shows,
You have an error in your SQL syntax 1064. i tried multiple combinations of above command, but still unable to do so.
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 '1' at line 1
The issue here is likely to be the space in the table name. Have you tried the following?
DROP TABLE `Customer 1`;