CREATE DATABASE statement to create the database. Before database creation, make sure that the logged-in user has CRAETEROLE permissions. For more information on permissions, see Managing User Permissions. A sample database can be created as follows:CREATE DATABASE test;
\\l.test database first by using the following statement.create table ttable (age int, id int);
test2 database with test as the template.CREATE DATABASE test2 TEMPLATE test;
test2, and you can see that ttable also exists in test2. Therefore, avoid creating any objects in template1, as those in template1 will also exist in databases created based on it. You can view all the tables in the selected database with \\d.
\\l.
DROP DATABASE. When you perform the deletion operation, make sure that the logged-in user is a superuser or a general user with the permission of database deletion. Note that the database can be deleted only if the number of its connections is 0; for example:

test2, the number of connections to test2 must be greater than or equal to 1. You can only delete test2 after switching to test.public when it is created. Tables with the same name cannot be created in the same database unless they are in different schemas. The database system identifies a table in the form of database.schema.table. In addition, schemas with the same name can be created in different databases.CREATE SCHEMA testschema;
public schema by default; for example:CREATE TABLE testschema.test;
ALTER DATABASE test set search_path to testshcema,public;
testschema of the test database to public mode and indicates that testschema has the highest priority. If no schema prefixes are added, testschema will be matched first.SET search_path TO public;
testschema, you can switch to public with this statement.DROP SCHEMA testschema;
CHECK constraint, which specifies that a data column must satisfy a certain expression, such as:CREATE TABLE products (product_no int, name text, price int CHECK(price > 0));
NOT NULL constraint, which specifies that a data column cannot be empty, such as:CREATE TABLE products (product_no int NOT NULL, name text NOT NULL, price int CHECK(price > 0));
DISTRIBUTED BY syntax to specify hash distribution when creating a table. This policy combines all the keys specified as hash distribution and determines the result of data distribution by the hash algorithm. The statement is as follows:CREATE TABLE test (id int, age int) DISTRIBUTED BY (id);
DISTRIBUTED RANDOMLY syntax to specify random distribution when creating a table. As the name suggests, this policy determines data distribution randomly. The statement is as follows:CREATE TABLE test (id int, age int) DISTRIBUTED RANDOMLY;
PRIMARY KEY or UNIQUE. For other columns, the first column will be used as the reference for data distribution by default, and the default data distribution policy will be hash distribution.CREATE VIEW testview AS SELECT * FROM ttable where age=28;
testview view with all rows in ttable that satisfy the condition "age=28".DROP VIEW testview;
Feedback