威斯尼斯人官网mysql alter table命令修改表结构实例

mysql ALTER TABLE myTable - DROP COLUMN Quantity, - DROP PRIMARY KEY;

多谢阅读此文,希望能支援到我们,多谢我们对本站的协助!

mysql实例之使用alter table命令改进表构造

mysql ALTER TABLE myTable - ADD COLUMN Quantity SMALLINT UNSIGNED NOT NULL, - MODIFY ID SMALLINT UNSIGNED NOT NULL, - ADD PRIMARY KEY (ID);

率先创设贰个表,SQL语句如下:

mysql CREATE TABLE myTable( - ID SMALLINT - );

再度使用desc命令查看表布局,我们开采上面的更改命令生效了:

实例意气风发:使用ALTER
TABLE命令向表中加多字段、更正字段类型甚至安装主键。

使用desc命令查看表布局:

mysql desc myTable;+-------+----------------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+----------------------+------+-----+---------+-------+| ID | smallint(5) unsigned | NO | | | |+-------+----------------------+------+-----+---------+-------+
mysql desc myTable;+-------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------+-------------+------+-----+---------+-------+| ID | smallint(6) | YES | | NULL | |+-------+-------------+------+-----+---------+-------+

实例二:在地点的实例底子上,大家删除myTable表中的Quantity字段和P奥迪Q5IMA锐界Y
KEY主键

查看表布局:

mysql alter
table语句能够改良表的主旨构造,例如增添字段、删除字段、增多主键、加多索引、改善字段数据类型、对表重命名等等操作,本小说通过五个简单的实例向大家介绍mysql
alter table的行使办法

应用ALTER
TABLE命令向表中增添字段、修正字段类型以至安装主键,SQL语句如下:

desc myTable;+----------+----------------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+----------+----------------------+------+-----+---------+-------+| ID | smallint(5) unsigned | NO | PRI | | || Quantity | smallint(5) unsigned | NO | | | |+----------+----------------------+------+-----+---------+-------+

发表评论

电子邮件地址不会被公开。 必填项已用*标注