How to Insert New Column in SQL?

Use `ALTER TABLE table_name ADD column_name data_type;`

Example: `ALTER TABLE employees ADD middle_name VARCHAR(50);`

Add multiple columns: `ALTER TABLE table_name ADD column1 data_type, ADD column2 data_type;`

Example: `ALTER TABLE employees ADD age INT, ADD hire_date DATE;`

Add a column with a default value: `ALTER TABLE table_name ADD column_name data_type DEFAULT default_value;`

Example: `ALTER TABLE employees ADD status VARCHAR(20) DEFAULT ‘active’;`

Add a column with `NOT NULL`: `ALTER TABLE table_name ADD column_name data_type NOT NULL;`

Example: `ALTER TABLE employees ADD department_id INT NOT NULL;`

Add a column at a specific position if supported by the database: `ALTER TABLE table_name ADD column_name data_type AFTER existing_column;`

Example: `ALTER TABLE employees ADD nickname VARCHAR(50) AFTER first_name;`

Add a column as the first column if supported by the database: `ALTER TABLE table_name ADD column_name data_type FIRST;`

Example: `ALTER TABLE employees ADD employee_code VARCHAR(20) FIRST;`

Check database-specific syntax before running the command

Suggested for You

Trending Today