- MySQL Document-Dark Horse Programmer (Tencent Weiyun): https://share.weiyun.com/RaCdIwas
- 1-MySQL foundation.pdf, 2-MySQL constraints and design.pdf, 3-MySQL multi-table query and transaction operation.pdf
- MySQL study notes 01 [database concept, MySQL installation and use] [day01]
- MySQL study notes 02 [SQL basic concepts and general grammar, database CRUD operations] [day01]
MySQL study notes 04 [database query operations, table constraints] [day01, day02]
MySQL study notes 05 [multi-table operation, three paradigms, database backup and restore] [day02]
MySQL study notes 06 [multi-table query, sub-query, multi-table query exercises] [day03]
MySQL study notes 07 [transaction, user management and authority management] [day03]
table of Contents
05 CRUD operations on database tables
Modify the table name: alter table table name rename to the new table name;
Modify the character set of the table: alter table table name character set character set name;
Add a column: alter table table name add column name data type;
Modify column name type: alter table table name change column name new column name new data type;
Delete column: alter table table name drop column name;
Client graphical interface tool SQLyog
Use SQLyog to log in to the database
Use SQLyog to operate the database
06 Basic operations recorded in database tables
05 CRUD operations on database tables
DDL_operation table_query
R(Retrieve): query
- Query all the table names in a database: show tables;
- Query table structure: desc table name; (description)
DDL_Operation Table_Create
Syntax:
create table table name (
column name 1 data type 1,
column name 2 data type 2,
...
column name n data type n
);Note: There is no need to add a comma (,) in the last column
Data field type
- int: integer type [age int]
- double: decimal type [score double(5, 2) up to 5 digits, 2 decimal places are reserved]
- date: date, including only year, month and day, yyyy-MM-dd
- datetime: date, including year, month, day, hour, minute and second yyyy-MM-dd HH:mm:ss
- timestamp: Timestamp type, including year, month, day, hour, minute and second, yyyy-MM-dd HH:mm:ss [If you do not assign a value to this field in the future, or assign it to null, the current system time will be used by default to automatically assign the value. 】
- varchar: string [name varchar(20): maximum name is 20 characters; zhangsan 8 characters, Zhang San 2 characters]
Create table
create table student(
id int,
name varchar(32),
age int,
score double(4,1),
birthday date,
insert_time timestamp
);
Copy table
Copy table: create table table name like the name of the table being copied;
DDL_Operation Table_Modify
U(Update): modify
- Modify the table name: alter table table name rename to the new table name;
- Modify the character set of the table: alter table table name character set character set name;
- Add a column: alter table table name add column name data type;
- Modify column name type: alter table table name change column name new column name new data type; alter table table name modify column name new data type;
- Delete column: alter table table name drop column name;
Modify the table name: alter table table name rename to the new table name;
Modify the character set of the table: alter table table name character set character set name;
Add a column: alter table table name add column name data type;
Modify column name type: alter table table name change column name new column name new data type;
Delete column: alter table table name drop column name;
DDL_Operation Table_Delete
D(Delete): delete
- drop table table name;
- drop table if exists 表名 ;
Client graphical interface tool SQLyog
SQLyog graphical tool-client
SQLyog is a simple, efficient and powerful graphical MySQL database management tool produced by the well-known Webyog company in the industry. Using SQLyog can quickly and intuitively allow you to maintain a remote MySQL database through the network from any corner of the world.
Use SQLyog to log in to the database
Use SQLyog to operate the database
06 Basic operations recorded in database tables
DML_Add data
Syntax: insert into table name (column name 1, column name 2, ... column name n) values (value 1, value 2, ... value n);
Note:
- The column name and value should correspond one to one.
- If the column name is not defined after the table name, the default value will be added to all columns [insert into table name values (value 1, value 2, ... value n);]
- Except for numeric types, other types need to be enclosed in quotation marks (both single and double).
DML_Delete data
Syntax: delete from table name [where condition]
note:
- If no conditions are added, all records in the table are deleted.
- If you want to delete all records
- delete from table name; - not recommended. There will be as many delete operations as there are records (low efficiency).
- TRUNCATE TABLE table name; - (recommended, more efficient) delete the table first, and then create the same table.
DML_Modify data
Syntax: update table name set column name 1 = value 1, column name 2 = value 2,... [where condition];
Note: If no conditions are added, all records in the table will be modified.