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;
    
  • 相关阅读:
    树型表的设计 上海
    FTP通讯封装 上海
    线程淡写 上海
    TCP通讯故障 上海
    设计模式引导 上海
    初试Delegate 上海
    c# 扫描端口 上海
    攻读计算机研究生的看法(转载) 上海
    挖掘表字段中的汉字 上海
    新生活运动 上海
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15039859.html
Copyright © 2011-2022 走看看