CREATE NOTEBOOK¶

Creates a new Snowflake notebook or replaces an existing notebook.

Syntax¶

CREATE [ OR REPLACE ] NOTEBOOK [ IF NOT EXISTS ] <name>
  [ VERSION '<version_alias_name>' ]
  [ FROM '<source_location>' ]
  [ MAIN_FILE = '<main_file_name>' ]
  [ COMMENT = '<string_literal>' ]
  [ DEFAULT_VERSION = '<version_name>' ]
  [ QUERY_WAREHOUSE = <warehouse_to_run_nb_and_sql_queries_in> ]
Copy

Required parameters¶

name

String that specifies the identifier (i.e. name) for the notebook; must be unique for the schema in which the notebook is created.

In addition, the identifier must start with an alphabetic character and cannot contain spaces or special characters unless the entire identifier string is enclosed in double quotes (for example, "My object"). Identifiers enclosed in double quotes are also case-sensitive.

For more information, see Identifier requirements.

Optional parameters¶

VERSION 'version_alias_name'

User specified version alias. An identifier sharing the same namespace with the auto-generated version name identifier. It must follow these rules:

  • Unique for the notebook in which the version is created.

  • Isn’t set to FIRST, LAST, or DEFAULT. These are reserved keywords.

  • Doesn’t start with version$. The auto-generated version names start with version$.

  • Doesn’t contain slashes.

The following are examples of valid version alias names:

  • 1.0.0

  • prod-1.1.0

FROM 'source_location

Location to copy the file from. This must be a Snowflake stage location.

If specified, a notebook object is created based on the copied file. If not specified, the notebook object is created from a template notebook.

If specified, the MAIN_FILE parameter must be set to the name of the file you want to copy. This file must be an ipynb file.

MAIN_FILE = 'main_file_name'

User-specified identifier for the notebook file name. This is separate from the notebook object name, which is specified in the name parameter. This file must be an ipynb file.

COMMENT = 'string_literal'

Specifies a comment for the notebook or version of the notebook.

Default: No value

DEFAULT_VERSION = 'version_name'

Sets the default version of the notebook (the version that gets invoked for EXECUTE NOTEBOOK). The version name is an identifier.

Default: LAST

QUERY_WAREHOUSE = warehouse_name

Specifies the warehouse where SQL queries in the notebook are run. This parameter is optional. However, it is required to run the EXECUTE NOTEBOOK command.

Access control requirements¶

A role used to execute this SQL command must have the following privileges at a minimum:

Privilege

Object

USAGE

Database

USAGE or OWNERSHIP

Schema

CREATE NOTEBOOK

Schema

Note that operating on any object in a schema also requires the USAGE privilege on the parent database and schema.

For instructions on creating a custom role with a specified set of privileges, see Creating custom roles.

For general information about roles and privilege grants for performing SQL actions on securable objects, see Overview of Access Control.

Usage notes¶

  • Regarding metadata:

    Attention

    Customers should ensure that no personal data (other than for a User object), sensitive data, export-controlled data, or other regulated data is entered as metadata when using the Snowflake service. For more information, see Metadata fields in Snowflake.

  • CREATE OR REPLACE <object> statements are atomic. That is, when an object is replaced, the old object is deleted and the new object is created in a single transaction.

Examples¶

The following creates a notebook named mynotebook:

CREATE NOTEBOOK mynotebook;
Copy

Although the QUERY_WAREHOUSE parameter is optional, specifying it is recommended when creating a new notebook so that EXECUTE NOTEBOOK can be run on the notebook.

CREATE NOTEBOOK mynotebook
 QUERY_WAREHOUSE = my_warehouse;
Copy

The following example creates a notebook from an ipynb file on a stage:

CREATE NOTEBOOK mynotebook;
 FROM '@my_db.my_schema.my_stage'
 MAIN_FILE = 'my_notebook_file.ipynb'
 QUERY_WAREHOUSE = my_warehouse;
Copy