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) ???
Asked
Active
Viewed 603 times
-2
-
This sounds like an [XY problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Why are you trying to cram two values into a single column? – ChrisGPT was on strike Jan 28 '18 at 12:38
-
2I see no genuine reason to do this. – Ravi Jan 28 '18 at 12:38
-
my columns name is (aaaa,bbb) i whant to add this as one column name – Rezo Kobaidze Jan 28 '18 at 12:42
-
is it possible to ADD column that has comma separated name? – Rezo Kobaidze Jan 28 '18 at 12:45
-
1If you insist on making everything more cumbersome: weird column names just need to be wrapped in backticks. (Again / future users: *don't do this*. Just a literal answer to the question title.) – mario Jan 28 '18 at 13:09
-
1This idea is beyond terrible. Don't do it. – Strawberry Jan 28 '18 at 13:10
-
im not asking if its bad or good idea i asked only if is it possible – Rezo Kobaidze Feb 01 '18 at 13:22
2 Answers
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
-
-
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