Home > Database > Mysql Tutorial > Summary of the use of common commands for mysql columns

Summary of the use of common commands for mysql columns

黄舟
Release: 2017-09-26 11:16:35
Original
8344 people have browsed it

The main content of this article is mysql column common commands:

  1. View table column attributesdescribe table_name column_name

  2. show all column property View the properties of all columns

  3. Modify the column properties of the table alter table

    modify
  4. rename columnRename column

  5. Add column (add index at the same time), delete column

  6. Modify the default value of the column


  7. 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;
    Copy after login

    Summary of the use of common commands for mysql columns

    show all column propertyView the properties of all columns


    show fields from springdemo.blog;
    Copy after login

    View all columns

    Summary of the use of common commands for mysql columns

    Modify the column attributes of the table alter table

    modify

    Modify the column attributes of the table alter table

    modify

    Summary of the use of common commands for mysql columns

    ##rename columnRename column


    Modify the field name of the table alter table

    change

    Summary of the use of common commands for mysql columns

    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 columns

    alter table springdemo.tb_ms_audit_user_infoadd mal_report int default 0comment '恶意举报的次数', add index(mal_report);
    Copy after login
    删除字段 : alter  table  <表名>  drop  <列名>
    Copy after login

    Modify the default value of the column

    alter table tablename alter column drop default; #(若本身存在默认值,则先删除)alter table tablename alter column set default &#39;t5&#39;;# (若本身不存在则可以直接设定)
    Copy after login
    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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template