Let's look at a picture below:
A table is an important object for storing data in a database. Therefore, table usage is very important. The following describes how to use a table.
To modify Database information, we can add, delete, modify, and query tables.
Add
Create Table table_name
Delete
Drop table table_name
Change
① Modify your own name: alter table table_name
② Operate fields through tables:
Modify the field name:
Alter table table
New column column_name
New_data_type
Add field:
Alter table table
Add {[column_definition] |
[Column_name ascomputed_column_expression]}
Delete field:
Alter table table
Drop column column_name
Query
Use the SELECT statement (I personally think it is more complicated, not to mention ...)
Database tables serve the people with the purpose of determining the integrity of database information through various conditions when modifying database information. The following describes various conditions: Constraints, rules, and default values.
Constraints:
Verification constraints: use expressions to determine input values to ensure data integrity (one field can use multiple check constraints)
constraint constraint_namecheck (logical_expression)
Logical_expression is the logical expression for verification.
Null constraint: whether a null value is allowed or not
Add null or not null to the data to be restricted.
Example:
Create Table student (student ID int not null, name char (8 ))
Deault constraint: Default Value Constraint
constraint constraint_namedefault constraint_expression[for column_name]
Example:
constraint de_order_quantitydeault 100 for order_quantity
Primary key constraint: A table has only one primary key constraint, but one primary key constraint can be set for one or more fields.
Uniqueness constraint: When a primary key constraint is set for a table, all the remaining information can be set as uniqueness constraints to ensure integrity.
Foreign key constraint: when multiple tables are associated and the primary keywords are defined at the same time, we can set them as foreign key constraints for convenience, compared with other tables, it becomes a keyword. (That is to say, the primary and external keywords are relatively speaking. Of course, the premise is that there are multiple tables)
The following is a graph of these constraints (it always feels like the painting is messy, and the more abstract the painting is .......)
The default value and rule are the same as the table's important objects in the database, but the task of the default value and rule is to add restrictions to the table (I don't know anything else, I just learned this... cainiao ..). Let's talk about it separately.
Default Value: Binding to a field or custom data type can help with insert operations that do not contain all data table fields
Rule: bind to a field or user-defined data type, and specify the fields that can accept those data values