-1

I Created the db with phpmyadmin and created 8 columns i forgot to create date column i tried to create it with this code and i got this

ALTER TABLE "users" ADD "cdate" DATE

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 '"users" ADD "cdate" DATE' at line 1

Dave
  • 5,108
  • 16
  • 30
  • 40
Ziyad Mhmd
  • 25
  • 1
  • 3
  • 2
    Table and column names should be enclosed with backticks not double quotes. – Dave Apr 07 '19 at 11:06
  • 2
    `ALTER TABLE users ADD cdate DATE` delete the double quotes – forpas Apr 07 '19 at 11:07
  • 1
    If you really want to use that syntax (which is not the default) you'd need to [enable ANSI_QUOTES](https://mariadb.com/kb/en/library/sql-mode/). – Álvaro González Apr 07 '19 at 11:08
  • Possible duplicate of [How to change column datatype in SQL database without losing data](https://stackoverflow.com/questions/5136013/how-to-change-column-datatype-in-sql-database-without-losing-data) – Yassine CHABLI Apr 07 '19 at 11:09

4 Answers4

1

You can Use phpmyadmin to add a new column without any code

Or Use this :

ALTER TABLE `users` ADD `cdate` DATE

You should use this ` not this "

0

you can add columns to existing table using phpmyadmin below the table structure you can find add [num] columns

and since you asked

ALTER TABLE `users` ADD `cdate` DATE
Talal
  • 394
  • 1
  • 13
0

Read about this in the documentation https://dev.mysql.com/doc/refman/8.0/en/alter-table.html

ALTER TABLE table_name ADD column_name column_definition
n0body7331
  • 33
  • 8
0

you dont need any qoute

ALTER TABLE users ADD cdate DATE

Backticks are to be used for table and column identifiers, but are only necessary when the identifier is a reserve word of mysql

Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63