table
A table is a fundamental structure in a relational database that organizes data into rows and columns, similar to a spreadsheet.
Definition
A table is a fundamental structure in a relational database that organizes data into rows and columns, similar to a spreadsheet. Each column has a defined data type (like text, numbers, or dates) and a name, while each row contains the actual data values. Tables are the primary way to store and organize data in databases like DuckDB.
Structure
In DuckDB, you create a table using the CREATE TABLE statement, which defines the table's schema (structure). The schema includes column names, their data types, and any constraints like primary keys, foreign keys, or not-null requirements. For example:
Copy code
CREATE TABLE employees (
id INTEGER PRIMARY KEY,
name VARCHAR NOT NULL,
hire_date DATE,
salary DECIMAL(10,2)
);
Temporary vs Persistent Tables
DuckDB supports both temporary tables that exist only for your current session and persistent tables that are saved to disk. Temporary tables are created using CREATE TEMPORARY TABLE and are automatically dropped when your connection closes.
Virtual Tables and Views
DuckDB also supports virtual tables through its view system, which appear like regular tables but are actually stored queries. While not physical tables, they behave similarly in queries:
Copy code
CREATE VIEW employee_salaries AS
SELECT name, salary
FROM employees
WHERE salary > 50000;
Table Functions
DuckDB extends the traditional table concept with table functions that can generate tables dynamically. These include functions like range() and generate_series() which create tables on the fly:
Copy code
SELECT * FROM range(1, 5);
This feature distinguishes DuckDB from traditional databases by making table generation more flexible and dynamic.
Related terms
The CREATE TABLE statement is a fundamental SQL command that defines a new table in a database, specifying its structure including column names, data types,…
Temporary table →A temporary table is a table scoped to a single session (or transaction) that is automatically dropped when the session ends, used for intermediate results that don't need to persist.
relational database →A relational database is a structured collection of data organized into tables with rows and columns.
ALTER TABLE statement →The ALTER TABLE statement allows you to modify the structure of an existing database table without having to recreate it from scratch.
CREATE TABLE AS SELECT (CTAS) →CREATE TABLE ... AS SELECT (CTAS) creates a new table and populates it in one statement, using the result of a query to define both its schema and its data.
Wide table →A wide table is a table with a large number of columns, typically produced by denormalizing and flattening related data together, common in analytics and columnar data warehouses.

