WHCSRL 技术网

MySQL数据库修改数据表

Modify table name
Syntax:
Alter table old table name rename new table name
View table in database
insert picture description here
Change tests to test
here Insert picture description
View change results
Insert picture description here
Modify fields The data type of
Syntax:
Alter table name modify the field that needs to be modified Why the data type is modified
Use desc to view the data type in the table
insert picture description here
change the name data type to varchar(30)
Insert picture description here
View the result of the change
in Insert picture description here
Modify field name
Syntax:
Alter table table name change old field name new field name new data type
Change deptif in the table to deptid
Insert picture description here
Add field
Syntax: New Alter table table name Type constraint
or:
Alter table table name add New field name data type constraint first (add an existing field name)
Add a field named loc

Add a loc1 field again
insert picture description here
delete field
Syntax:
Alter table table name drop field name
delete loc1 field
Insert picture description here
Modify the sort position of the field
Syntax:
Alter table table name modify field name data type first (put it in the first place )
or:
Alter table table name modify field name data type after field name 2
put the loc field in the first place
insert picture description here
Change the storage engine of the table
Syntax:
Alter table table name engine=Changed engine
Change the test engine to MyISAM

insert picture description here
Foreign key to insert picture description here><br><br>Constraints Table name drop foreign key Foreign key constraint<br> Create a foreign key and delete<br> <img src=
insert picture description here
delete unrelated tables
Syntax:< br> Drop table if exists Table 1, Table 2
insert picture description here
delete The main table associated with other tables
Create two tables first
insert picture description here
When we delete the main When table, you will find that there are foreign key constraints on the main table and cannot be deleted directly
insert picture description here
The main table can be deleted only when the sub-table constraint is lifted and the sub-table is deleted.insert picture description here< /p>

推荐阅读