Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to add a column into a table in MySQL?

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    Sometimes we need to add a column that we require into the table. We can do this by using ADD keyword with ALTER command.

    Syntax:

    To add a column into a table, use the following syntax:

    ALTER TABLE table_name
    ADD COLUMN column_name datatype;
    

    Example: Suppose we have a table user as below:

    user
    
    id  user_name     country  
    .......................................
    1   John           Canada 
    2   Chris          America    
    3   Joy            London     
    4   Jenny          Korea       
    

    Now we want to add the column named "age" into the "user" table.

    We use the following statement:

    ALTER TABLE user
    ADD COLUMN age int(11);
    

    Result: The "user" table will now look like as below:

    id  user_name     country      age
    ..................................
    1   John           Canada    
    2   Chris          America     
    3   Joy            London      
    4   Jenny          Korea   
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: