Typical mysql operations on tables

Source: Internet
Author: User
Mysql commonly used NEXTONE: createcreatetabletesttable (idint (10) notnullauto_incrementprimarykeycomment, namevarchar (20) notnullcharactersetutf8comment, age? Intnullcomment, genderchar (2) coment, gmt_createdda

Mysql commonly used operations on tables NEXTONE: create table testtable (id int (10) not null auto_increment primary key comment '', name varchar (20) not null character set utf8 comment '', age? Int null comment '', gender char (2) coment'', gmt_created da

Common mysql operations on tables
  1. NEXTONE: create
    Create table testtable (
    Id int (10) not null auto_increment primary key comment '',
    Name varchar (20) not null character set utf8 comment '',
    Age? Int null comment '',
    Gender char (2) coment '',
    Gmt_created datetime not null comment''
    ) Engine = innoDB default charset = utf8;
  2. Set the increment sequence: auto_increment
    Set the primary key: primary key
    Label: comment.
    Set the field is not empty: not null
    Set the field be empty: null
    Format: character set utf8
    Char fixed length variable length, varchar
    Time type: datetime
  3. NEXTTWO: insert, updae, delete, select pass
  4. NEXTTHREE: alert:
    1. delete column
    ? Alter talbe table drop column
    2. alert rename
    ? Alter table rename new_table
    3. alter drop primary key
    ? Alter table drop primary key
    4. alter add primary key
    ? Alter table sj_resource_charges add constraint pk_sj_resource_charges primary key (resid, resfromid)
    5. add column
    ? Alter table add column_name type not null comment''
    6. change column type
    ? Alter table change column_name new_column_name type not null comment''
    7. alter index_name
    ? Alter table add colunm index_name (index_column_name)
    8. alter drop index emp_name
    ? Alter table drop index index_column_name
    NEXTFOUR:
    Drop
    Structure of the drop statement will delete tables are dependent constraints (constrain), trigger (trigger), index (index) depends on the table;
    The stored procedure/function will be retained, but to the invalid state.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.