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`,...);
Related
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'
I'm trying to alter a table from int to varchar using
ALTER TABLE shares
ALTER COLUMN link VARCHAR(255) NOT NULL;
Currently getting the error message
#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 'VARCHAR(255) NOT NULL' at line 2
If you're using MySQL, then the syntax should be:
ALTER TABLE table_name MODIFY COLUMN column_name datatype;
so:
ALTER TABLE shares MODIFY COLUMN link VARCHAR(255) NOT NULL;
The syntax you were using was for SQL Server.
ALTER TABLE table_name ALTER COLUMN column_name datatype;
Try with following query :
ALTER TABLE shares MODIFY COLUMN link VARCHAR(255) NOT NULL;
ALTER TABLE `shares`
MODIFY COLUMN `link` VARCHAR(255) NOT NULL;
That's work only if the old table definition have data that will be compatible with the new definition of the column
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 :)
Sql keeps throwing me a syntax error and I can't seem to figure out whats wrong.
ALTER TABLE `productList` ALTER COLUMN `ASIN` VARCHAR(32);
The error is the normal sql syntax error
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 'VARCHAR(32)' at line 1
Try this:
ALTER TABLE `productList` MODIFY COLUMN `ASIN` VARCHAR(32);
The syntax to change the column name is
ALTER TABLE tablename MODIFY COLUMN new-column-definition
You need to use MODIFY COLUMN instead of ALTER COLUMN if you want to change the column definition.
https://dev.mysql.com/doc/refman/5.1/en/alter-table.html
It's modify, not alter column.
ALTER TABLE table_name
MODIFY column_name column_definition
[ FIRST | AFTER column_name ];
When running
ALTER TABLE my_table modify column my_column int(10) NOT NULL DEFAULT 0;
I've got the error message:
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(10) NOT NULL DEFAULT 0' at line 1.
How can this issue being fixed?
ALTER TABLE ... MODIFY COLUMN ... does not allow renaming the column; this is why the name of the column must be provided only once (the current name).
In order to rename the column (besides other changes you may want to operate on it, like changing its type) you have to use ALTER TABLE ... CHANGE COLUMN ... and provide the current and the new name of the column.
See the documentation page of the ALTER TABLE statement for more explanation and examples.
Try this code
ALTER TABLE my_table CHANGE mycolumn my_column INT( 10 ) NOT NULL DEFAULT '1';