-4

as the title says, I'm having trouble about adding a column into a table, and I thought you could help me.

The column I'm trying to add is for a server, a gaming one I'd rather say, and for some reason INSERT INTO and ADD don't seem to work. INSERT INTO gives me an error message, but ADD doesn't even seem to exist as a command.

ALTER TABLE users
INSERT INTO users (Color)

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 '' at line 2

Community
  • 1
  • 1
Presiune
  • 3
  • 1
  • 2

2 Answers2

2

INSERT is a DML(Data Manipulation Language) command, you need to use DDL(Data Definition Language) command instead. Like below :

ALTER TABLE users
ADD COLUMN Color varchar(50)
Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55
  • This still does not work. Again, ADD just doesn't seem to be a command in my DataBase. And the error I get is: #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 'ADD COLUMN users (Color)' at line 1 – Presiune Aug 12 '19 at 09:35
  • @Presiune please check again. – Barbaros Özhan Aug 12 '19 at 09:36
  • 1
    It does indeed work now, thank you a lot. – Presiune Aug 12 '19 at 09:46
0

This is how you have to add a new column into an existing table in mysql

ALTER TABLE tabel_name ADD COLUMN new_field_name <data_type>

So your modify query has to be like this:

ALTER TABLE users ADD COLUMN color varchar(10)
Kazmi
  • 1,198
  • 9
  • 20