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;
    
  • 相关阅读:
    用Html+Js实现的“自动补全”功能
    利用js为table添加行
    Flex 当鼠标悬停在DataGrid某行上时用datatoolField显示当前行
    Flex中设置编译器参数
    Linux2 在Linux(CentOS)上配置SSH免登陆
    线程笔记
    I/O
    网络编程
    Linux基础
    进程间的通信
  • 原文地址:https://www.cnblogs.com/zz-newbie/p/15039859.html
Copyright © 2011-2022 走看看