Many ways to add column to existing table in MySQL. If you r using GUI tools, add column to table in MySQL is easy. If you are using CLI, then here’s the command to add column in MySQL table.
To add column in existing table, you may refer to the 2 examples below:-
Advertisements
Example I: Add new varchar column to the end of the table
ALTER TABLE `tablename_here` ADD `new_column_name` VARCHAR( 255 ) NOT NULL ;
Example II: Add new integer column after an existing column in table
ALTER TABLE `tablename_here` ADD `new_column_name` INT NOT NULL AFTER `existing_column` ;
It’s simple to add column to existing table right? 🙂
Related posts:
Prestashop 1.6: "Unexpected token <" error when upload category thumbnail
Symfony2: How to get Doctrine Entity Manager in Console command
Turn on MySQL query cache to speed up query performance?
How to restore MySQL database from sql dump file?
How to install SVN 1.6 on CentOS 5
How to sort drop down - Admin Generator - Symfony 1.4
How to shrink worksheet for printing in Calc - OpenOffice
How to print screen in Asus Zenfone 6
Share this with your friends:-
ok. I already know how to do it:
alter table table_name add column user_id int, add foreign key(user_id) references user(id);
and if the new key is a constraint, like a foreign key?