I am trying to add column in mysql table but following error thrown.
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 'ALTER TABLE cm_article ADD COLUMN active INT NOT NULL DEFAULT '0' AFTER description'
My Sql Statement is:
ALTER TABLE cm_article ADD COLUMN active INT NOT NULL DEFAULT '0' AFTER description;
There are two different types of quotation marks in MySQL. You need to use ` for column names and ' for strings. Since you have used ' for the filename column the query parser got confused.
ALTER TABLE `cm_article` ADD COLUMN `active` INT NOT NULL DEFAULT '0' AFTER `description` ;
I would do :
ALTER TABLE cm_article
ADD COLUMN active INT NOT NULL DEFAULT(0)
AFTER description;
If it doesn't work, modify 'ADD COLUMN' with just 'ADD'
Related
I want to change the column "ID" which is currently type INTEGER but have NULL values into type INTEGER NOT NULL AUTO_INCREMENT. But I am getting error. My SQL syntax is as follows.
ALTER TABLE users
ALTER COLUMN ID INTEGER NOT NULL AUTO_INCREMENT;
The above code is giving me syntax error.
Then I tried,
ALTER TABLE users
ALTER COLUMN ID INTEGER NOT NULL;
This is also giving me syntax error like
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 'INTEGER NOT NULL' at line 2
Use MODIFY COLUMN:
ALTER TABLE users
MODIFY COLUMN ID INTEGER NOT NULL AUTO_INCREMENT;
There's also an ALTER COLUMN type of command, but it's only for specifying the DEFAULT for a column. Refer to https://dev.mysql.com/doc/refman/8.0/en/alter-table.html for examples.
Query :
ALTER TABLE db.tbl_name ALTER COLUMN column_name INT NULL
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 'INT NULL' at line 1
Please try the following:
ALTER TABLE db.tbl_name Modify COLUMN column_name INT NULL
This is a good read :)
I'm trying to add a gender column to my table with this query:
ALTER TABLE QRCodeUser ADD gender CHAR(1) enum('M','F') NOT NULL;
I get 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 'enum('M','F') NOT NULL' at line 1
What's my mistake?
Try this (you dont need to specify the size, char(1) ) :
ALTER TABLE QRCodeUser ADD gender enum('M','F') NOT NULL;
Correct usage of syntax:
ALTER TABLE table_name ADD column_name enum(`field1`,`field2`,...);
IF COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` ADD `name` INT(32) UNSIGNED NOT NULL;
END
I am trying to write some sql that will insert a column name into the table "Characters" if it is not already existant, however I am getting errors which I do not understand (quite new to SQL) and I could use some help understanding why it is not working. I have gotten the IF part from another Question, and the ALTER part from the DBMS I'm using, PhpMyAdmin 2.11.4.
It is using MySQL 5.6 apparently and this is 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 'IF COL_LENGTH('Characters', 'name') IS NULL
BEGIN
ALTER TABLE `Characters` AD' at line 1
I tried to add a column at end of the table assestbl
ALTER TABLE `assestbl` ADD `timestamp` VARCHAR NOT NULL DEFAULT CURRENT_TIMESTAMP
but its showing an 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 'NOT NULL DEFAULT CURRENT_TIMESTAMP' at line 1
You have two errors:
1) syntax error in datatype, varchar needs defined length: VARCHAR(LEN)
once you fix that you get something like invalid default value for 'timestamp':
2) DEFAULT CURRENT_TIMESTAMP can only be applied to temporal datatypes (DATE,TIME,DATETIME,TIMESTAMP and YEAR).