Create, change, empty and remove a table
CREATE defines an object, ALTER changes its definition, TRUNCATE removes its rows, and DROP removes the object.
Understand the idea
Read the object name before running a changing command. These examples use a disposable table, not ORDERS. CREATE fails if the name already exists; choose a new name rather than adding OR REPLACE blindly.
| Concept | What it means |
|---|---|
| CREATE | Define a new table. |
| ALTER | Change an existing definition. |
| TRUNCATE | Empty all rows while keeping the table. |
| DROP | Remove the table object. |
A concrete example
DESC shows ID and NOTE. COUNT returns 0 after TRUNCATE. After DROP, the table no longer exists; SELECT from it would fail. Run in an idle learning session, outside unrelated transactions.
Remember: TRUNCATE empties the table. DROP removes the object itself.
Explain it step by step · full theory
Understand the idea
Read the object name before running a changing command. These examples use a disposable table, not ORDERS. CREATE fails if the name already exists; choose a new name rather than adding OR REPLACE blindly.
Snowflake transaction behavior is more useful than memorizing generic DDL/DML labels. CREATE, ALTER and DROP run as separate transactions and can implicitly commit active work. Snowflake treats TRUNCATE as DML for transaction purposes. Do not assume a later ROLLBACK undoes a DROP.
Words used in this lesson
- CREATE
- Define a new table.
- ALTER
- Change an existing definition.
- TRUNCATE
- Empty all rows while keeping the table.
- DROP
- Remove the table object.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Create, change, empty and remove a table
Choose the input
CREATE defines an object, ALTER changes its definition, TRUNCATE removes its rows, and DROP removes the object.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Choose the input
CREATE defines an object, ALTER changes its definition, TRUNCATE removes its rows, and DROP removes the object.
- Apply the SQL
Read the object name before running a changing command. These examples use a disposable table, not ORDERS. CREATE fails if the name already exists; choose a new name rather than adding OR REPLACE blindly.
- Explain the result
TRUNCATE empties the table. DROP removes the object itself.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Before running this lesson
Use an authorized learning account and warehouse. VALUES examples need no stored tables. Object-changing examples use separate disposable tables in L2_OBJECTS_LAB.SALES from the first lesson; run each setup once with a fresh name.
Lifecycle of one disposable table
CREATE TEMPORARY TABLE L2_OBJECTS_LAB.SALES.DDL_PRACTICE (ID NUMBER);
ALTER TABLE L2_OBJECTS_LAB.SALES.DDL_PRACTICE ADD COLUMN NOTE VARCHAR;
INSERT INTO L2_OBJECTS_LAB.SALES.DDL_PRACTICE VALUES (1, 'practice');
DESC TABLE L2_OBJECTS_LAB.SALES.DDL_PRACTICE;
TRUNCATE TABLE L2_OBJECTS_LAB.SALES.DDL_PRACTICE;
SELECT COUNT(*) AS ROWS_LEFT FROM L2_OBJECTS_LAB.SALES.DDL_PRACTICE;
DROP TABLE L2_OBJECTS_LAB.SALES.DDL_PRACTICE;What to expect and why
DESC shows ID and NOTE. COUNT returns 0 after TRUNCATE. After DROP, the table no longer exists; SELECT from it would fail. Run in an idle learning session, outside unrelated transactions.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Which command keeps the table definition but removes all rows?
Compare your reasoning
TRUNCATE empties the table. DROP removes the object itself.