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

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 294
    Comment on it

    Sometimes we need to drop a column that we don't need further from the table. We can do this by using DROP keyword with ALTER command.

    Syntax:

    To drop/delete the column from a table, use the following syntax:

    ALTER TABLE table_name
    DROP COLUMN column_name;
    

    Example: Suppose we have a table user as below:

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

    Now we want to delete the column named "age" in the "user" table. For that we use the below statement

    ALTER TABLE user
    DROP COLUMN age;
    

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

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

    Hope this will help you :)

 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: