📅  最后修改于: 2020-11-30 01:03:43             🧑  作者: Mango
在本节中,我们将讨论如何在PostgreSQL中创建数据库。
在PostgreSQL中,我们可以通过两种方式创建数据库:
要在pgAdmin中创建数据库,我们将遵循以下步骤:
步骤1
数据库→创建→数据库
第2步
第三步
第四步
在PostgreSQL中创建数据库的完整语法如下:
CREATE DATABASE db_name
OWNER = role_name
TEMPLATE = template
ENCODING = encoding
LC_COLLATE = collate
LC_CTYPE = ctype
TABLESPACE = tablespace_name
CONNECTION LIMIT = max_concurrent_connection
在以上语法中,我们具有以下参数:
Parameters | Description |
---|---|
db_name | We will use this parameter to specify the new database name, which we want to create. And we also ensure that the database must be unique because If we try to create a new database with the same name as an existing database, it will show an error. |
role_name | It is used to describe the role name for the user who will have the new database, and by default, it is postgres. |
Template | While creating the new database, we will require database template name. |
Encoding | It is used to describe the character set encoding for the new database, and by default, it is UTF8. |
Collate | It is used to define the sort order of strings that mark the result of the ORDER BY clause if we are using a SELECT statement. |
Ctype | This parameter is used to display the character classification for the new database. |
tablespace_name | It is used to define the tablespace name for the new database, and by default, it is the template database’s tablespace. |
max_concurrent_connection | This parameter is used to define the maximum parallel connections of a new database, and by default, it is -1 (unlimited). |
使用create database命令时,我们可能会遇到以下错误:
要在命令行中创建数据库,我们将遵循以下步骤:
步骤1
第2步
第三步
之后,输入以下命令创建数据库
CREATE DATABASE Javatpoint;
第四步
要获取先前创建的所有数据库的列表,我们将输入以下命令:
\l
第5步
要连接到数据库,我们将输入以下命令:
\c javatpoint