zoukankan      html  css  js  c++  java
  • MySQL之常用SQL语句

    -- 将sid移动到第一行
    alter table student modify sid int first;
    -- 将sage移动到ssex后面
    alter table student modify sage int not null after ssex;
    
    -- 添加删除主键
    alter table student add primary key(sid);
    alter table student drop primary key;
    
    -- 添加删除唯一约束1
    alter table student add unique(sname);                                   
    alter table student drop index sname;
    alter table student drop key sname;
    -- 添加唯一性约束2
    alter table student add constraint uk unique key student(sname);
    -- 添加联合唯一索引
    alter table student add constraint double_uk unique index double_uk1(sname,ssex);
    
    -- 添加删除自增
    alter table student modify sid int auto_increment;
    alter table student modify sid int;
    
    -- 添加删除外键
    alter table student add constraint fk1 foreign key(sphone) references teacher(tid);
    alter table student drop foreign key fk1;
    
    -- 添加删除非空约束
    alter table student modify sage int not null;
    alter table student modify sage int;
    
    -- 修改字段名称及属性
    alter table student change sssex ssex char(2) default '男';
    
    -- 添加删除默认值
    alter table student modify sssex char(2) default '男';
    alter table student modify sssex char(2);                                             
    
    -- 查看表结构
    describe student;
    -- 查看索引
    show keys from student;
    -- 查看表源码
    show create table student;
    
    -- 修改表的存储引擎
    -- ALTER TABLE tb_name ENGINE=存储引擎名称
    ALTER TABLE user12 ENGINE=MyISAM;
    
    -- 修改自增长的值
    -- ALTER TABLE tb_name AUTO_INCREMENT=值
    ALTER TABLE user12 auto_increment=100;
    
    -- 如果表存在就删除
    drop table if exists tablename;
    
  • 相关阅读:
    更新glibc,删除libc库后,命令行都不能使用了
    进程和线程、协程的区别
    PMP项目管理--资源管理
    清除缓存 echo 1/2/3 > /proc/sys/vm/drop_caches
    gdb malloc方法
    随时更新---能力集
    输出gdb调试信息到文件中
    主动生成core文件 gcore +pid
    PMP项目管理--风险管理
    linux后台程序
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15039859.html
Copyright © 2011-2022 走看看