Marko
Marko

Reputation: 57

Sql query - how to create column in table

I have in Msql database several tables with lots of rows and columns in them. I need to create a new column in one of these tables.

How do I create an SQL query for inserting a new column in a specific table via PhpMyAdmin?

Upvotes: 1

Views: 4854

Answers (5)

Ares
Ares

Reputation: 1461

Syntax:

ALTER TABLE tableName ADD columnName columnType;

Example:

ALTER TABLE people ADD hometown VARCHAR(50);

You can use this query in phpMyAdmin by going to the SQL tab after selecting your database.

Also, you may use the graphical user interface to add a column by following the steps:

  • Select the database on the left side of the screen
  • Select the table on the left side of the screen
  • Go to the "Structure" tab
  • Under the list of all existing columns, you have the option to add new fields (columns)

Upvotes: 2

lollancf37
lollancf37

Reputation: 1125

The command is ALTER TABLE, you can find the details here

Upvotes: 0

evan
evan

Reputation: 12535

ALTER TABLE tbl_name ADD [COLUMN] col_name column_definition [FIRST | AFTER col_name ]

Link: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

Upvotes: 0

DivinesLight
DivinesLight

Reputation: 2415

Simple google revealed this and this

ALTER TABLE contacts ADD email VARCHAR(60);

Upvotes: 0

Nicola Cossu
Nicola Cossu

Reputation: 56357

alter table table_name add column new_column int after id

In my example I have added a new column that has data type int after id column. Very easy.

Upvotes: 5

Related Questions