Home>Article>Database> How to modify column attributes in mysql

How to modify column attributes in mysql

WBOY
WBOY Original
2021-12-27 17:25:43 11501browse

In mysql, you can use the "ALTER TABLE table name MODIFY COLUMN column attribute after the column name is changed" statement to modify the column attributes. The ALTER command is used to modify the data table name or modify the data table field. When the parameter When set to an attribute value, the data attribute of the specified column will be modified.

How to modify column attributes in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to modify column attributes in mysql

In mysql, if you want to modify column attributes, you can use the alter command.

Modify field type:

How to modify column attributes in mysql

1: Delete column: ALTER TABLE [Table name] DROP [Column name]

How to modify column attributes in mysql

2: Add a column: ALTER TABLE [Table name] ADD [Column name] INT NOT NULL COMMENT 'Comment description'

How to modify column attributes in mysql

3: Modify the column Type information: ALTER TABLE [Table name] CHANGE [Column name] [New column name (you can use the same name as the original column here)] BIGINT NOT NULL COMMENT 'Comment'

4: Rename the column: ALTER TABLE [Table name] CHANGE [Column name] [New column name] BIGINT NOT NULL COMMENT 'Comment description'

5: Rename the table: ALTER TABLE [Table name] RENAME [Table new name]

6: Delete the primary key in the table: Alter TABLE [Table name] drop primary key

Recommended learning:mysql video tutorial

The above is the detailed content of How to modify column attributes in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn