Before you begin
Before reading this page, do the following:- or .
- .
Create a database
Database objects make up the first level of the . To create a database, use a , following the database best practices. After reviewing the best practices, see the examples we provide below.Cockroach Labs recommends against starting a database name with the string
cluster:. Refer to Database Best Practices for more information.Database best practices
Here are some best practices to follow when creating and using databases:- Do not use the preloaded
defaultdbdatabase. Instead, create your own database with aCREATE DATABASEstatement, and change it to the SQL session’s by executing aUSE {databasename};statement, by passing the--database={databasename}flag to the , or by specifying thedatabaseparameter in the passed to your database schema migration tool. - Do not begin your database name with the string
cluster:. If your database name begins with this string, you must append the following to the URI connection string to :&options=-ccluster=system - Create databases and as a member of (e.g., as the ), and create all other lower-level objects as a , with fewer privileges, following .
- Limit the number of databases you create. If you need to create multiple tables with the same name in your cluster, do so in different , in the same database.
- Use a or the instead of a to execute .
Example
Create an empty file with the.sql file extension at the end of the filename. This file will initialize the database that will store all of the data for the MovR application.
For example:
dbinit.sql in a text editor, and, at the top of the file, add a CREATE DATABASE statement:
movr, if one does not already exist.
To execute the statement in the dbinit.sql file as the root user, run the following command:
movr database.
For guidance on creating user-defined schemas, see .

