Article Directory
-
- 1. Database (additions and deletions)
- 2. Data Sheet
-
- 2.1 Create a data table
- 2.2 View table structure
- 2.3 View table data
- 2.4 Modify the table name
- 2.5 modify the data type of the field
- 2.6 Modify the field name (and field data type)
- 2.7 add fields
- 2.8 Delete fields
- 2.9 Delete the foreign key constraint of the table
- 2.10 Add data
- 2.11 Delete data
- 2.12 Modify data
- note
1. Database (additions and deletions)
1.1 Create a database
Create a database: CREATE DATABASE database name;
1.2 Delete the database
Delete database: drop database database name;
1.3 Display database
Display the database name: show databases;
1.4 Using the database
Use database: use database name;
2. Data Sheet
View all tables contained in the current database: SHOW TABLES;
2.1 Create a data table
Create a stu student table (number, name, gender, date of birth, test results)
(unique—unique) when there is a unique need, add the word unique;
create table stu(
id int primary key auto_increment, – student number, set id as the primary key, and increment
name varchar(50) unique, – student name (guarantee that the student’s name cannot be repeated)
gender char(1), – student gender
birthday date,-date of birth
score double-test score
)
2.2 View table structure
View table structure: desc+table name;
2.3 View table data
select * from 表名;
2.4 Modify the table name
Modify the table name: alter table old table name rename to new table name;
2.5 modify the data type of the field
Modify the data type of the field: alter table table name modify attribute name data type;
2.6 Modify the field name (and field data type)
Modify the field name (and field data type): alter table table name change old attribute name new attribute name new data type;
2.7 add fields
Add fields: alter table table name add attribute name 1 data type [integrity constraint condition] [first | after attribute name 2];
2.8 Delete fields
Delete field: alter table table name drop attribute name;
2.9 Delete the foreign key constraint of the table
Delete the foreign key constraint of the table: alter table table name drop foreign key foreign key alias;
2.10 Add data
INSERT INTO database name VALUES();
2.11 Delete data
Delete data: delete from where element of library name;
2.12 Modify data
Modify data: update library name set what and where;
note
Note: 1. If CHANGE does not change the field name, only the field type is modified. CHAGE must be followed by two identical field names.
2. To modify the data structure of the field, use MODIFY, if you want to modify the field name + data structure, use CHANGE.
MySql data structure:
https://blog.csdn.net/m0_47605113/article/details/110630847
The data type and the operation of the primary and foreign key constraints will be updated later.
Hope you all pay attention, thank you! ! !