How to solve #1064 error in MySQL? - mysql

I got MySQL syntax Error 1064 while I am add new column.
ALTER TABLE `customerdetails` ADD `mobile` DOUBLE(12) NOT NULL ;
where customerdetails is the name of the table.
The Error message 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 ') NOT NULL' at line 1
Can somebody help me to solve this problem?

When you are defining column type as DOUBLE you have to define how many decimal places it will use
ALTER TABLE customerdetails ADD mobile DOUBLE(12,2) NOT NULL ;
Also first number (Characteristic) needs to be bigger than second number (Mantissa)

Related

Add calculated column to mySQL table

I'm trying to add column 'new_id' to table 'items_backup' with the following MySQL expression:
ALTER TABLE `items_backup`
ADD COLUMN `new_id` DOUBLE
GENERATED ALWAYS AS (`id`*100) STORED;
It is the multiplication of column 'id' by 100.
This is returning the error:
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 'GENERATED ALWAYS AS (`id`*100) STORED' at line 3
MySQL Version: 5.6.51
Can anyone help?

Add the column in mysql and has the same data like the column existing

I want to add the column name "payroll_date_on" in the table and has the default value as the other table column named "jo_time_on".
ALTER TABLE jobs ADD COLUMN payroll_time_on INT(11) AS (jo_time_on) PERSISTED;
While running this I got an error code
Error Code: 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 'AS (jo_time_on) PERSISTED' at line 1
Help me to solve this error and clone the column jo_time_on
I am using the mysql version 5.6.38
try this:
ALTER TABLE jobs ADD COLUMN payroll_time_on INT(11);
UPDATE TABLE SET payroll_time_on = jo_time_on;

setting a constraint

ALTER TABLE Customers
ADD COLUMN ZipCode INT CONSTRAINT CHK_ZipCode
CHECK ( [ZipCode] LIKE '[0-9][0-9][0-9][0-9][0-9]')
Error Code: 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 '[ZipCode] LIKE '[0-9][0-9][0-9][0-9][0-9]')' at
line 3
it said '[' not valid , expecting an expression
how do i solve this?
In MySQL, you would express this as:
ALTER TABLE Customers
ADD COLUMN ZipCode INT CONSTRAINT CHK_ZipCode CHECK (ZipCode REGEXP '^[0-9](5}$');
The syntax you are using looks like SQL Server.

Trying to apply "Not null" and "default" in MYSQL

I am trying to create a column in a table in MySQL that cannot be a null value, and also has a default value. But when trying to, it just shows an error in syntax:
Create table example (
code int(10),
name varchar(20) not null default('My company')
);
And this is my error message:
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 '('My company')
)' at line 3
Problem seems to be the default part.
I have removed the parentheses and it works for me. Verified in sql fiddle here:
http://sqlfiddle.com/#!9/5e571a

MySQL query with enum values

I've the following structure in MySQL 5.6.19.
CREATE TABLE `metadata` (
`md5` char(32) NOT NULL,
`match` enum('none','md5','similarity') DEFAULT NULL
)
And I got an error doing a query like this:
select * from metadata where match = 'md5';
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 '= 'md5'' at line 1
There're multiple entries in the table and rows that could match the query. But MySQL refuse to do it. Any idea about the reason?
Thanks!
MATCH is reserved keyword in MySQL: http://dev.mysql.com/doc/mysqld-version-reference/en/mysqld-version-reference-reservedwords-5-5.html. You should enclose your field name in backticks to make it work:
select * from metadata where `match` = 'md5';