<commit_before>.. _sql_ddl_create:

===============
Creating tables
===============

.. rubric:: Table of contents

.. contents::
   :local:

Basics
======

To create a table use the ``CREATE TABLE`` command. You must at least specify a
name for the table and names and types of the columns.

See :ref:`data-types` for information about the supported data types.

This query creates a simple table with two columns of type ``integer`` and
``text``::

    cr> create table my_table (
    ...   first_column integer,
    ...   second_column text
    ... );
    CREATE OK, 1 row affected (... sec)

A table can be removed by using the ``DROP TABLE`` command::

    cr> drop table my_table;
    DROP OK, 1 row affected (... sec)

The ``DROP TABLE`` command takes the optional clause ``IF EXISTS`` which
prevents the generation of an error if the specified table does not exist::

    cr> drop table if exists my_table;
    DROP OK, 0 rows affected (... sec)


.. _sql_ddl_schemas:

Schemas
=======

Tables can be created in different schemas. These are created implicitly on
table creation and cannot be created explicitly. If a schema did not exist yet,
it will be created.

You can create a table called ``my_table`` in a schema called ``my_schema``
schema like so::

    cr> create table my_schema.my_table (
    ...   pk int primary key,
    ...   label text,
    ...   position geo_point
    ... );
    CREATE OK, 1 row affected (... sec)
<commit_msg>Link create/drop table mentions to sql reference for these statements<commit_after>.. _sql_ddl_create:

===============
Creating tables
===============

.. rubric:: Table of contents

.. contents::
   :local:

Basics
======

To create a table use the :ref:`ref-create-table` command. You must at least
specify a name for the table and names and types of the columns.

See :ref:`data-types` for information about the supported data types.

This query creates a simple table with two columns of type ``integer`` and
``text``::

    cr> create table my_table (
    ...   first_column integer,
    ...   second_column text
    ... );
    CREATE OK, 1 row affected (... sec)

A table can be removed by using the :ref:`drop-table` command::

    cr> drop table my_table;
    DROP OK, 1 row affected (... sec)

The :ref:`drop-table` command takes the optional clause ``IF EXISTS`` which
prevents the generation of an error if the specified table does not exist::

    cr> drop table if exists my_table;
    DROP OK, 0 rows affected (... sec)


.. _sql_ddl_schemas:

Schemas
=======

Tables can be created in different schemas. These are created implicitly on
table creation and cannot be created explicitly. If a schema did not exist yet,
it will be created.

You can create a table called ``my_table`` in a schema called ``my_schema``
schema like so::

    cr> create table my_schema.my_table (
    ...   pk int primary key,
    ...   label text,
    ...   position geo_point
    ... );
    CREATE OK, 1 row affected (... sec)

{'fraction_non_alphanumeric': 0.11940800538176925, 'fraction_numerical': 0.0026908846283215607, 'mean_word_length': 3.0851648351648353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7370318', 'n_tokens_mistral': 877, 'n_tokens_neox': 829, 'n_words': 400}