-4

How can I create multiple columns in a table from a list?

table name: teachers

column names list:

first_name
last_name
email
phone
age
birthday
school
district
subject
...
...
...

how can I create those columns with VARCHAR (20) all null in my table?

John Jaoill
  • 159
  • 2
  • 9
  • 2
    This looks like **[XY Probem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem)**. Describe what case do you want to solve. Creating tables on the fly sounds somehow as poor design. Of course it is doable using dynamic SQL. Also storing `age` and `birthday` as string is very bad idea. – Lukasz Szozda Aug 12 '17 at 16:26

2 Answers2

1

To CREATE a table, one would do:

CREATE TABLE pet (first_name VARCHAR(20), last_name VARCHAR(20),
   email VARCHAR(255), phone VARCHAR(20), age INT, birthday DATE, school VARCHAR(100), etc...);
Stuart
  • 6,630
  • 2
  • 24
  • 40
0

I just used this code from here: https://stackoverflow.com/a/20655740/4357238

ALTER TABLE users
ADD COLUMN log VARCHAR(12) NOT NULL,
ADD COLUMN status INT(10) UNSIGNED NOT NULL,
ADD COLUMN count SMALLINT(6) NOT NULL
AFTER lastname
John Jaoill
  • 159
  • 2
  • 9