Bulk loading: files become table rows
COPY INTO a table reads staged files with warehouse compute and stores their records as rows.
Understand the idea
Use this separate M6_LAB schema throughout the module. Setup deliberately avoids OR REPLACE: inspect existing objects or choose a fresh schema when repeating the lab.
| Concept | What it means |
|---|---|
| Stage | Holds or points to files. |
| File format | Defines how records are parsed. |
| Warehouse | Processes the load. |
| Table | Stores typed rows after loading. |
A concrete example
Two orders worth 20 and 35 become two rows with a total of 55.
Remember: Uploading a file does not load a table. Check both the COPY result and the stored rows.
Explain it step by step · full theory
How to apply it
Use this separate M6_LAB schema throughout the module. Setup deliberately avoids OR REPLACE: inspect existing objects or choose a fresh schema when repeating the lab.
Use the Module 03 database and a warehouse your role can use. Setup requires CREATE SCHEMA, then CREATE TABLE, STAGE and FILE FORMAT in the schema. A separate loader needs database/schema/warehouse USAGE, target INSERT, stage READ and file-format USAGE; verification also needs SELECT. External stages use USAGE and the Module 05 cloud integration permissions.
Words used in this lesson
- Stage
- Holds or points to files.
- File format
- Defines how records are parsed.
- Warehouse
- Processes the load.
- Table
- Stores typed rows after loading.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Bulk loading: files become table rows
Understand the input
COPY INTO a table reads staged files with warehouse compute and stores their records as rows.
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
- Understand the input
COPY INTO a table reads staged files with warehouse compute and stores their records as rows.
- Follow the example
Two orders worth 20 and 35 become two rows with a total of 55.
- Check the outcome
Uploading a file does not load a table. Check both the COPY result and the stored rows.
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
Manual examples only. Start with this module’s first lesson to create L2_OBJECTS_LAB.M6_LAB. In each new SQL session select that schema and an authorized warehouse. Later lessons state additional prerequisites. Upload file contents through Snowsight or a supported client; never run CSV as SQL.
One-time SQL setup
USE DATABASE L2_OBJECTS_LAB;
CREATE SCHEMA M6_LAB;
USE SCHEMA M6_LAB;
CREATE STAGE M6_FILES;
CREATE FILE FORMAT M6_CSV TYPE=CSV SKIP_HEADER=1
FIELD_OPTIONALLY_ENCLOSED_BY='"';
CREATE TABLE M6_ORDERS (ORDER_ID NUMBER, AMOUNT NUMBER(10,2));What to expect and why
Creates empty lab objects. Select your authorized warehouse before querying files or loading.
Save as orders.csv
order_id,amount
1,20.00
2,35.00What to expect and why
Save as UTF-8 text locally; these are file contents, not SQL.
Upload from a supported client
PUT file:///absolute/path/orders.csv @L2_OBJECTS_LAB.M6_LAB.M6_FILES/base/ AUTO_COMPRESS=FALSE;What to expect and why
Replace the local path. Alternatively upload orders.csv to base/ in this internal stage through Snowsight. Keep the filename unchanged.
Load and reconcile
USE SCHEMA L2_OBJECTS_LAB.M6_LAB;
LIST @M6_FILES/base/;
COPY INTO M6_ORDERS FROM @M6_FILES/base/
FILES=('orders.csv') FILE_FORMAT=(FORMAT_NAME='M6_CSV');
SELECT COUNT(*) AS ROWS_LOADED, SUM(AMOUNT) AS TOTAL FROM M6_ORDERS;What to expect and why
For the first load into the fresh table, expect 2 rows and total 55. COPY also reports file status and rows loaded. A retry may skip the already loaded file.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain why LIST can show orders.csv while M6_ORDERS remains empty.
Compare your reasoning
The file exists, but no successful COPY has inserted its rows.