In SQL, adding a new column is simple in syntax but critical in impact. Whether you’re adapting a schema to evolving requirements or correcting a data model, the operation must be deliberate. Every column you introduce alters storage, performance, and downstream dependencies.
To create a new column in an existing table, use ALTER TABLE. Define the data type to match the actual domain of values. Set constraints where possible to protect data integrity. Avoid using overly broad types like TEXT or BLOB unless the column truly requires them.
Example in PostgreSQL:
ALTER TABLE users
ADD COLUMN last_login TIMESTAMP WITH TIME ZONE DEFAULT now();
This adds a last_login column to the users table with a default value. In production, consider indexing the column if it will be queried often. Plan for NULL handling—either allow it and manage in application logic, or prevent it with NOT NULL.