Databases, schemas and tables
A database groups related data objects. A schema organizes objects inside that database. A table holds rows and columns, such as one row for each order.
Understand the idea
Think of a database as a library, a schema as a section, and a table as a structured register. A row is one entry in the register. A column describes one property, such as an order amount. Decide what one row represents before designing the columns.
| Concept | What it means |
|---|---|
| Database | A named container for schemas, such as L2_OBJECTS_LAB. |
| Schema | A namespace inside a database, such as SALES. |
| Table | Rows with named, typed columns, such as ORDERS. |
| Qualified name | DATABASE.SCHEMA.OBJECT identifies the exact object. |
A concrete example
Northstar keeps its sales orders in L2_OBJECTS_LAB.SALES.ORDERS. Another schema can also have a table named ORDERS without being the same table.
Remember: Use the full name to identify the data; use a warehouse to process it.
Explain it step by step · full theory
Understand the idea
Think of a database as a library, a schema as a section, and a table as a structured register. A row is one entry in the register. A column describes one property, such as an order amount. Decide what one row represents before designing the columns.
A database is not a virtual warehouse. The database organizes stored objects; a warehouse supplies compute. Suspending the warehouse does not delete this hierarchy. Access also follows boundaries: a role generally needs USAGE on the database and schema plus the relevant privilege on the table.
The first SQL block is a guided setup. CREATE defines the containers and table; INSERT adds the two sample rows; SELECT reads them. You do not need to memorize all of these commands yet. The following lessons explain types and queries before returning to changes and recovery choices.
Follow the example
The example creates an isolated learning database and a sales schema. CREATE commands need suitable creation privileges. Do not substitute a production database. If the lab name already exists, use a fresh name consistently instead of replacing existing objects.
After inserting two orders, SELECT reads their amounts. ORDER BY makes the displayed order predictable. Fully qualified names keep this example independent of the current database and schema. Later examples explicitly say when they depend on these objects.
With this fresh setup, the result is order 101 with 40.00 and order 102 with 60.00. The table has two rows; the total amount is 100.00.
Words used in this lesson
- Database
- A named container for schemas, such as L2_OBJECTS_LAB.
- Schema
- A namespace inside a database, such as SALES.
- Table
- Rows with named, typed columns, such as ORDERS.
- Qualified name
- DATABASE.SCHEMA.OBJECT identifies the exact object.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Databases, schemas and tables
Start with the requirement
Northstar keeps its sales orders in L2_OBJECTS_LAB.SALES.ORDERS. Another schema can also have a table named ORDERS without being the same table.
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
- Start with the requirement
Northstar keeps its sales orders in L2_OBJECTS_LAB.SALES.ORDERS. Another schema can also have a table named ORDERS without being the same table.
- Choose the objects
Compare the responsibilities: Database: A named container for schemas, such as L2_OBJECTS_LAB.; Schema: A namespace inside a database, such as SALES.; Table: Rows with named, typed columns, such as ORDERS.
- Explain the outcome
Use the full name to identify the data; use a warehouse to process it.
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
Examples are for reading first. Optional execution requires an authorized learning account, a selected warehouse for queries, and privileges on the named objects. Nothing runs on this website.
Read the example
CREATE DATABASE L2_OBJECTS_LAB;
CREATE SCHEMA L2_OBJECTS_LAB.SALES;
CREATE TABLE L2_OBJECTS_LAB.SALES.ORDERS (ORDER_ID NUMBER, AMOUNT NUMBER(10,2));
INSERT INTO L2_OBJECTS_LAB.SALES.ORDERS VALUES (101, 40.00), (102, 60.00);
SELECT ORDER_ID, AMOUNT FROM L2_OBJECTS_LAB.SALES.ORDERS ORDER BY ORDER_ID;What to expect and why
With this fresh setup, the result is order 101 with 40.00 and order 102 with 60.00. The table has two rows; the total amount is 100.00.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Explain why SALES.ORDERS and SUPPORT.ORDERS can coexist in the same database.
Compare your reasoning
The schemas are separate namespaces. Include database, schema and table to identify one specific object; ORDERS alone depends on session context.