The query ran. The result was close. But the schema was missing something essential. A new column.
Adding a new column to a database table is routine, but it carries weight. It changes structure, performance, and future queries. Whether you use PostgreSQL, MySQL, or a distributed system, the core steps stay the same.
First, define the purpose. Name the column with precision. Use snake_case or lowerCamelCase to match your schema conventions. Choose the data type with care—INTEGER, TEXT, BOOLEAN, TIMESTAMP—because changing it later can be costly.
In SQL, the syntax is direct:
ALTER TABLE users ADD COLUMN last_login TIMESTAMP;
Run it in a migration, not in production ad hoc. In high-load systems, use tools that support online schema changes. In PostgreSQL, ALTER TABLE locks writes for the table during the operation. For massive tables, consider adding the column as nullable first, then backfilling in batches.