top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to insert a column in a existing table in MySQL

+2 votes
62 views
posted May 11, 2013 by Salil Agrawal

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

3 Answers

+2 votes
 
Best answer

User Alter table command.
Example -
ALTER TABLE table_name MODIFY column_name datatype

answer May 15, 2013 by Sudheendra
+1 vote

Add a column
ALTER TABLE name_of_the_table ADD column_name VARCHAR(size_of_the_column_name);

answer Jan 5 by Ajay Kumar
0 votes

To add column at end of the table

ALTER TABLE table_name ADD column_name VARCHAR(10);

To insert a new column after a specific column, use this statement

ALTER TABLE table_name ADD new_column_name VARCHAR(10) AFTER existing_column_name;

If you want the new column to be first, use this statement:

ALTER TABLE table_name ADD column_name  VARCHAR(10) FIRST;
answer Dec 21, 2016 by Atindra Kumar Nath
Similar Questions
+2 votes

How I 'll check how many rows inserted into every second on an average in a table of MySQL database?

+5 votes

How can I insert the content of excel file into MySQL Table, any pointer?

+1 vote

I have a table in Mysql DB like following

mysql> describe APPTBL;
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| APP_ID      | int(11)     | NO   | PRI | NULL    | auto_increment |
| CREATE_DATE | date        | YES  |     | NULL    |                |
| CLOSE_DATE  | date        | YES  |     | NULL    |                |
| ACTION      | text        | YES  |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+

While Starting of App, i am inserting the app details with CREATE_DATE and when it is closing, i am updating its CLOSE_DATE. But in case if user is restarting the app, i want to update NULL in place of CLOSE_DATE column. Here is my query,

mysql> update APPTBL set CLOSE_DATE = NULL where APP_ID = 1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0
mysql> select * from APPTBL ;
+-----------+-------------+------------+------------+
|   APP_ID  | CREATE_DATE | CLOSE_DATE |   ACTION   |
+-----------+-------------+------------+------------+
|    1      |  2013-10-08 | NULL       | XXXXXYYYYY |
+-----------+-------------+------------+------------+
1 row in set (0.00 sec)

But why i am not getting any result in this??

mysql> select * from APPTBL where CLOSE_DATE = NULL;
Empty set (0.00 sec)

Also, as i am writhing a java program using this where

rs = st.executeQuery("update APPTBL set CLOSE_DATE = NULL where APP_ID = 1");
if(!rs.wasNull()){
   // Why it is coming here??
}
+1 vote

Using Workbench with MySQL 5.6 how do I edit a existing Trigger. Do I need
to DROP the Trigger and create a new one ? If that is the case how can you
run start command in a live environment ?


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#470/147, 3rd Floor, 5th Main,
HSR Layout Sector 7,
Bangalore - 560102,
Karnataka INDIA.
QUERY HOME
...