欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql对表惯用操作

程序员文章站 2022-06-11 16:40:12
...

mysql对表常用操作 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 da

mysql对表常用操作
  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 table rename new_table
    3.alter drop primary key
    ?alter table 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 table add column_name type not null comment ''
    6.change column type
    ?alter table table change column_name new_column_name type not null comment ''
    7.alter index_name
    ?alter table table add colunm index_name(index_column_name)
    8.alter drop index emp_name
    ?alter table 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.