修改mysql數(shù)據(jù)庫表結(jié)構(gòu)的方法:1、查看表結(jié)構(gòu);2、添加列;3、刪除列,代碼為【mysql> alter table student drop column birthday】;4、修改列,代碼為【mysql> alter table】。
本教程操作環(huán)境:windows7系統(tǒng)、mysql8.0.22版,該方法適用于所有品牌電腦。
相關免費學習推薦:mysql數(shù)據(jù)庫(視頻)
修改mysql數(shù)據(jù)庫表結(jié)構(gòu)的方法:
1、查看表結(jié)構(gòu)
mysql> show create table student; +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Table | Create Table | +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | student | CREATE TABLE `student` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `NAME` varchar(20) NOT NULL, `AGE` int(11) NOT NULL, PRIMARY KEY (`ID`) ) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8 | +---------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.09 sec)
2、添加列
mysql> alter table student add column birthday datetime; Query OK, 0 rows affected (2.06 sec) Records: 0 Duplicates: 0 Warnings: 0
3、刪除列
mysql> alter table student drop column birthday; Query OK, 0 rows affected (0.80 sec) Records: 0 Duplicates: 0 Warnings: 0
4、修改列
--1.修改列的類型 mysql> alter table student modify age int not null; Query OK, 0 rows affected (0.09 sec) Records: 0 Duplicates: 0 Warnings: 0 --2.修改列的名稱 mysql> alter table student change column name sname varchar(20); Query OK, 0 rows affected (1.31 sec) Records: 0 Duplicates: 0 Warnings: 0
相關免費學習推薦:編程視頻