基础操作
    一:MySQL基础操作
        1:MySQL表复制
            复制表结构 + 复制表数据
            create table t3 like t1;  --创建一个和t1一样的表,用like(表结构也一样)
            insert into t3 select * from t1;  --t1的数据全部拿过来,注意是表结构一致才select* ,否则选择相应的的字段列插入
             
            create table t1(
                id int unsigned not null auto_increment primary key,
                name varchar(30)
            );
        2:MySQL索引(create不能创建主键索引,得用alter,建议全部用alter创建索引)
            *设置主键后默认就是主键索引
            一:alter table用来创建普通索引,unique索引或primary key索引
                普通索引:alter table t1 add index in_name(name)   --t1表中的那么字段添加索引名为in_name
                唯一索引:alter table t1 add unique(name)   --不给名字,默认是字段名
                          alter table t1 add unique un_name(name)
                           
                主键索引(自增才有意义):alter table t1 add primary key(id)
                         主键索引不是自增记得改成自增:alter table t1 modify id int unsigned not null auto_increment;
                 
                查看:show index from t1;
                删除:alter table t1 drop index in_name;
                 
                @*删除主键索引单独处理*
            二:alter table table_name drop index index_name
                    alter型删除索引:alter table t1 drop index in_name;
                     
                    @*删除主键索引*:
                    注意:删除主键索引的时候,如果你的主键索引是自增(如:id)删除是会报错的
                          实在想玩的话就把主键的auto_increment消掉
                          alter table t1 modify id int unsigned not null;
                          接着删除主键:alter table t1

相关文章:

  • 2022-02-16
  • 2022-02-26
  • 2021-10-04
  • 2022-01-30
  • 2021-04-14
  • 2021-06-15
  • 2021-11-02
  • 2021-12-09
猜你喜欢
  • 2021-12-09
  • 2021-04-29
  • 2021-11-28
  • 2022-02-09
  • 2022-02-17
  • 2022-02-19
相关资源
相似解决方案