postgresql.txt(国外英文资料).doc
文本预览下载声明
postgresql.txt(国外英文资料)
The definition of a table:
For any relational database, tables are the most core and fundamental object unit of data storage. Lets start here.
Create a table:
The CREATE TABLE products (
Product_no integer,
The name text,
Price numeric
);
Delete table:
DROP TABLE products;
Create a table with default values:
The CREATE TABLE products (
Product_no integer,
The name text,
Price numeric DEFAULT 9.99 -- DEFAULT is the keyword, and then 9.99 is the DEFAULT value for field price.
);
The CREATE TABLE products (
Product_no SERIAL, - the field of SERIAL type indicates that the field is a self-increasing field that is exactly the same as the Sequence in Oracle.
The name text,
Price numeric DEFAULT is 9.99
);
The output is:
NOTICE: CREATE TABLE will CREATE implicit sequence products_product_no_seq for serial column products.product_no
4. The constraints:
The check constraint is the most common constraint type in the table, which allows you to declare that the value in a field must satisfy a Boolean expression. Not only that, but we can also declare table level check constraints.
The CREATE TABLE products (
Product_no integer,
The name text,
The value of the price field must be greater than 0, otherwise the field value will be inserted or modified to cause an error. Also, the check constraint is required
This is an anonymous constraint that does not show the naming constraint when the table definition is defined, so that PostgreSQL will be based on the current table name, field name, and constraint type,
Name the constraint automatically, for example: products_price_check.
Price numeric CHECK (price 0)
);
The CREATE TABLE products (
Product_no integer,
The name text,
The check constraint for this field is shown as positive_price. This is done when the constraint is maintained in the future.
Price numeric CONSTRAINT positive_price CHECK (price 0)
);
The following constraint is non-null constraint, which is that the field of the constraint cannot insert t
显示全部