NeroCube / bookmark

Place some learning resources
0 stars 0 forks source link

How to Add Columns to a Table Using MySQL ADD COLUMN Statement #252

Open NeroCube opened 3 years ago

NeroCube commented 3 years ago

MySQL ADD COLUMN examples First, we create a table named vendors for the demonstration purpose using the following statement:

CREATE TABLE IF NOT EXISTS vendors (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255)
);

Code language: SQL (Structured Query Language) (sql) Second, we add a new column named phone to the vendors table. Because we specify the position of the phone column explicitly after the name column, MySQL will obey this.

ALTER TABLE vendors
ADD COLUMN phone VARCHAR(15) AFTER name;

Reference: https://www.mysqltutorial.org/mysql-add-column/