-2

i want to add column inside table. column name is name,surname how i can add this column inside already created table? like alter table MyTable ADD name,surname Varchar(100) ???

2 Answers2

4

Add two separate columns:

alter table mytable add name varchar(100);
alter table mytable add surname varchar(100);

Simply concatenate the values together if you want them in a list:

select concat_ws(', ', surname, name) as surname_name

Don't combine them into a single column.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • my columns name is aaaaa,bbbbb its coma separated – Rezo Kobaidze Jan 28 '18 at 12:41
  • 1
    @RezoKobaidze . . . Break it up at the application layer. It contains two separate elements. Each should have its own column (or row). – Gordon Linoff Jan 28 '18 at 12:42
  • i know but is it possible to ADD column that has comma separated name??? – Rezo Kobaidze Jan 28 '18 at 12:43
  • 1
    @RezoKobaidze . . . You can use backticks. They are the escape character in MySQL. But don't do it! If you want two parts to a name, separate them with an underscore: `name_surname`. That makes it much easier to query in the future. – Gordon Linoff Jan 28 '18 at 12:47
0
ALTER TABLE tablename ADD COLUMN `name,age` VARCHAR(45) NULL DEFAULT NULL;

Name, age has to be between negation symbols. I type it here but it is not showing up on UI after I post it. Here ` is the one above tab on keyboard.

Anything inside those negation symbols is considered as a column name.

pirho
  • 11,565
  • 12
  • 43
  • 70