MySQL-MySQL Data Management DML-Database 02
Wai Jian (understand)
ALTER TABLE table ADD CONSTRAINT constraint name FOREIGN KEY (column as a foreign key) REFERENCES that table (which field)
Physical external health, not recommended (to avoid trouble caused by too many databases)
Best Practices
The database is a simple table, as long as the data is stored
Want to use data from multiple tables, and want to use external health to solve with business logic
DML language
Add to
INSERT INTO table name (field 1, field 2, field 3) VALUES (value 1, value 2, value 3), (...);
Precautions:
Use commas to separate fields and fields
Fields can be omitted, but the following fields must be one-to-one correspondence
You can insert multiple pieces of data. The values after values can be separated by ()
modify
UPDATE 表名 SET column_name =value,[id=66] where [条件]
Condition: where clause operator id is equal to a certain value, greater than a certain value, modified in a certain interval
Operator returns boolean
Operator | meaning | range | result |
---|---|---|---|
= | equal | 5=8 | false |
<> or! = | not equal to | 5<>7 | True |
> | |||
< | |||
<= | |||
>= | |||
BETWEEN…and… | Within a certain range | 【2,5】 | |
AND | && | 5>1and 1>2 | False |
OR | || | 5>1or 1>2 | True |
Precautions:
colnum_name is a column of the database, try to bring it with you··
Condition, the filter condition is not specified will modify all categories
value is a specific value or a variable
delete
delete from 表名 where
Empty a database table, the structure and index of the table will not change
TRUNCATE table name
The difference between delete and truncate:
The same point: can delete data, will not delete the table structure
Different: truncate resets, increments the column, the counter will be reset to 0, does not affect the transaction.
delete delete problem: restart the database
InnoDB auto-increment column will start from 1 (stored in memory, power loss will be lost)