The main content of this article is mysql column common commands:
View table column attributesdescribe table_name column_name
-
show all column property View the properties of all columns
-
Modify the column properties of the table alter table
modify rename columnRename column
Add column (add index at the same time), delete column
Modify the default value of the column
View the attributes of the table columndescribe table_name column_name
Many times we need to view the column Details, for example:
describe springdemo.blog title;
show all column propertyView the properties of all columns
show fields from springdemo.blog;
View all columns
Modify the column attributes of the table alter table
modify
Modify the column attributes of the table alter table
modify ##rename columnRename column
Modify the field name of the table alter table
change
Note: The storage of data in the database has a great relationship with the data type, so do not change the data type casually alter table springdemo.blog change title title_new nvarchar(60) comment 'Modified';
Add (add index at the same time), delete columnsalter table springdemo.tb_ms_audit_user_infoadd mal_report int default 0comment '恶意举报的次数', add index(mal_report);
删除字段 : alter table <表名> drop <列名>
Modify the default value of the columnalter table tablename alter column drop default; #(若本身存在默认值,则先删除)alter table tablename alter column set default 't5';# (若本身不存在则可以直接设定)
Be sure to indicate the source when reprinting, and respect the work of others.
The above is the detailed content of Summary of the use of common commands for mysql columns. 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