0

I cannot change databases column

My Env

MacOS Mojave, MySQL Server version: 10.1.39-MariaDB Source distribution

why

Making a CRUD app, but I want to change table column, from text to desc, so I searched and used alter command, but right SQL command returns error messages.

My table

MariaDB [cake_cms]> describe interns;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(11)      | NO   | PRI | NULL    | auto_increment |
| email    | varchar(255) | NO   |     | NULL    |                |
| name     | varchar(64)  | NO   |     | NULL    |                |
| text     | varchar(255) | NO   |     | NULL    |                |
| location | varchar(64)  | YES  |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+
MariaDB [cake_cms]> Alter Table interns Rename Column text to desc;
ERROR 1064 (42000): 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 'Column text to desc' at line 1

Refered

https://www.dbonline.jp/mysql/table/index18.html
says to use

ALTER TABLE table_name
CHANGE COLUMN old_name TO new_name;

Rename a column in MySQL This site says:

ALTER TABLE tableName RENAME COLUMN "oldcolname" TO "newcolname" datatype(length);

So I write

alter table interns rename column "name" to "newname" varchar(255);

But returned syntax error message....

I do not know what to do. Please help me!

Ilyes
  • 14,640
  • 4
  • 29
  • 55
KAEDE
  • 340
  • 3
  • 10

1 Answers1

0

desc is a sql command so you can't name your table like this

Naminee
  • 157
  • 1
  • 15
  • alter table interns rename column "name" to "newname" varchar(255); also causes the error – KAEDE Aug 13 '19 at 12:30
  • 1
    try: ALTER TABLE table CHANGE COLUMN name newName varchar(5) – Naminee Aug 13 '19 at 12:38
  • ```MariaDB [cake_cms]> alter table interns change column name newName varchar(5); Query OK, 6 rows affected, 2 warnings (0.02 sec) Records: 6 Duplicates: 0 Warnings: 2``` It worked!! Thankyou !!! – KAEDE Aug 13 '19 at 12:57
  • Backtics (`) are what you put around column names, not quotes (") or ('). – Rick James Aug 13 '19 at 18:02