Knowledge Guide
HomeDatabasesSQL Fundamentals

ALTER

ALTER

In SQL, the ALTER statement is used to modify the structure of an existing database object, such as a table.

It allows you to add, modify, or drop columns, constraints, or other elements of a table without having to drop and recreate the entire table.

The basic syntax for the ALTER statement varies depending on the specific modification you want to make. Here are some examples.

Adding a column

To add a new column in a database table, you can use the ALTER command like this

ALTER TABLE table_name ADD column_name data_type;

This statement adds a new column with the specified name and data type to the existing table.

Example

Suppose we have an employees table with the column id, firstName, lastName as shown below:

Image
Image

by using ALTER, we can add a new column salary like this:

ALTER TABLE Employees ADD salary INT;

After the query execution the Employee table will look like this:

Image
Image
🤖 Don't fully get this? Learn it with Claude

Stuck on ALTER? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **ALTER** (Databases) and want to truly understand it. Explain ALTER from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **ALTER** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **ALTER** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **ALTER** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes