首頁  >  文章  >  資料庫  >  如何修改mysql資料庫表結構

如何修改mysql資料庫表結構

coldplay.xixi
coldplay.xixi原創
2020-12-15 14:56:112562瀏覽

修改mysql資料庫表結構的方法:1、檢視表結構;2、新增列;3、刪除列,程式碼為【mysql> alter table student drop column birthday】;4、修改列,程式碼為【mysql> alter table】。

如何修改mysql資料庫表結構

本教學操作環境:windows7系統、mysql 8.0.22版、thinkpad t480電腦。

相關免費學習推薦:mysql資料庫#(影片)

修改mysql資料庫表結構的方法:

1、檢視表格結構

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

相關免費學習推薦:程式設計影片

以上是如何修改mysql資料庫表結構的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn