Keywords used in SQL statements and table creation constraints

1. Keywords

in : followed by a set or subquery
like : it is only used in string columns, indicating fuzzy matching of strings
      %: indicating that there can be 0 or more characters where % appears_
      : indicating that _ appears There is and can only be one arbitrary character
all and any : followed by a set or subquery
exists : it is not used with any column, followed by a subquery. If the subquery can find the result, then the condition is Established, the result cannot be found. The condition is not established.
The conditional connector
and : means and or
: means or
between value1 and value2 : the value of value1 is smaller than the value of value2. Value1 and value2 are generally numeric types, and can also be dates, indicating that the value is within value1
is null between value2 : Indicates that the condition is true when the value is empty.
Is not null : Indicates that the value is not a spatial condition.
Order by sorting column 1. asc means ascending order 2. desc means descending order
Aggregation function:
count (column name |*| Constant): It finds the number of records (number of data items)
max (column name): takes the maximum value
min (column name): takes the minimum value
avg (column name): takes the average
sum (column name): sum
distinct : deduplication keyword
group by : grouping keyword, followed by the grouping column name, which can be one grouping column or multiple columns
having : it is performed on the grouped data Filtering, aggregate functions can be used in conditional expressions
. Union: Take all elements in two sets.
Union all : Indicates taking the union of two sets, without deleting duplicate elements.
Union : Taking the union of two sets, deleting duplicate elements.
Intersection: Take the elements of the overlapping parts of the two sets.
Intersect : Represents the intersection.
Difference set: All elements of the first set minus the elements of the overlapping parts of the two sets .
Minus : Represents the difference set.

2. Constraints

1. not null non-null constraint

         Column name data type not null --Row-level constraint syntax

        not null: indicates that the value of this column cannot be empty

        Note: not null is the only row-level constraint and cannot be written as a table-level constraint.

2. unique unique constraint

        Column name data type unique --row-level constraint syntax

        Unique: Indicates that the value of this column is unique and non-repeatable in the data of the entire table.

3. primary key primary key constraints

        Column name data type primary key --row-level constraint syntax

        Primary key: It is a combination of not null and unique, which means that the value of this column cannot be empty and cannot be repeated.

4. foreign key foreign key constraints

        Column name data type references main table name (primary key column of main table) -- row-level constraint syntax

        foreign key: indicates that the value of this column can only be obtained from the value of the primary key column of the main table

5. check check constraints

        Column name data type check (constraints) -- row-level constraints

        check: indicates that the value of this column must satisfy the constraints behind check

Add comments to the table

comment on table table name is 'comment';

comment on column table name. column name is 'comment';

Guess you like

Origin blog.csdn.net/weekendholiday/article/details/128102926