Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Add Drop Update Column Operation in SQL

Add Drop Update Column Operation in SQL

Here’s a complete guide to perform Add, Drop, and Update (Modify) column operations in SQL using the ALTER TABLE command.


? 1. Add Column

Used to add a new column to an existing table.

? Syntax:

ALTER TABLE table_nameADD column_name data_type [constraints];

? Example:

ALTER TABLE employeesADD email VARCHAR(100);

? 2. Drop Column

Used to delete an existing column from a table.

? Syntax:

ALTER TABLE table_nameDROP COLUMN column_name;

? Example:

ALTER TABLE employeesDROP COLUMN email;

?? Caution: This will permanently delete all data in that column.


? 3. Update (Modify) Column

Used to change the data type, size, or constraints of a column.

? MySQL Syntax:

ALTER TABLE table_nameMODIFY COLUMN column_name new_data_type;

? PostgreSQL Syntax:

ALTER TABLE table_nameALTER COLUMN column_name TYPE new_data_type;

? SQL Server Syntax:

ALTER TABLE table_nameALTER COLUMN column_name new_data_type;

? Example:

-- MySQLALTER TABLE employeesMODIFY COLUMN name VARCHAR(150);-- PostgreSQLALTER TABLE employeesALTER COLUMN name TYPE VARCHAR(150);

? Extra: Rename a Column (Optional)

? MySQL 8+ / PostgreSQL / SQL Server:

ALTER TABLE employeesRENAME COLUMN old_name TO new_name;

? Summary Table

OperationSyntax (MySQL)Purpose
AddALTER TABLE t ADD col TYPE;Add a new column
DropALTER TABLE t DROP COLUMN col;Remove a column
ModifyALTER TABLE t MODIFY col NEWTYPE;Change type/size/constraint
RenameALTER TABLE t RENAME COLUMN old TO new;Rename a column

Let me know your SQL dialect (MySQL, PostgreSQL, SQL Server, etc.) if you want tailored examples or full code with sample data!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql