Sql
DDL: Data definition language CREATE DROP ALTER
DML: Data Manipulation language SELECT INSERT UPDATE DELETE
DCL: Data Control Language GRANT REVOKE COMMIT ROLLBACK
The most basic (build a library, build a table)
SHOW DATABASES;
Use database name;
CREATE database name;
DROP database name;
SHOW TABLES; <<<<<<<< need to switch databases first
CREATE TABLE [library name.] Table Name (Field 1 property, Field 2 property,......)
CREATE TABLE [library name.] Table name like [library name.] Table name <<<<<<< Create a new table by a table in a library
Craete TABLE [library name.] Table name as SELECT field 1, Field 2 .... from [library name.] Table name; >>>>>>>>>>>
DROP TABLE [library name.] Table name
DESC [library name.] Table name
Alter command
Role: Modify the table's field properties
1. Add a new field
Format: ALTER table name ADD field property
2. Delete fields
Format: ALTER table name DROP field
3. Modify field names
Format: ALTER table name change field New Field property
4. Add Index
Set PRIMARY key: ALTER table name ADD PRIMARY key (field)
Set index: ALTER table name ADD index [index name] (field)
Set UNIQUE constraint: ALTER table name ADD unique [index name] (field)
5. Add foreign keys
Format: ALTER table name 1 ADD froeign KEY (field) REFERENCES Table 2 (field)
6. Delete Index
Delete primary key: ALTER table name DROP PRIMARY key
Delete index: ALTER table name DROP index name
Delete foreign key: ALTER table name DROP FOREIGN key
Insert command
Role: Adding records
Format: INSERT into table name (Field 1, Field 2,.....) Values (value 1, value 2 ...), (value 1, value 2 ...),......
Delete one or more records
DELETE from table name condition
Update command
Role: Modifying data in a table
Attention:
UPDATE is typically used in conjunction with where, order by, and limit
Format:
UPDATE table name SET field 1= value, field 2= value ... [Where to judge condition]
UPDATE table name SET field 1= value, field 2= value ... [ORDER BY judging condition]
Ps: Welcome To correct me, thank you.
Basic use of MySQL