zoukankan      html  css  js  c++  java
  • Mysql基本语句的总结

    1---------------创建一个表------------------------------------

    drop table if exists 表名

    create   table 表名(
     id int(11) primary key auto_increment,
     name varchar(20) not null
    );
     
    2---------------修改一个表的表名------------------------------------
    alter table 表名1 rename to 表名2
    解释:将表名1改为表名2
    demo:
              alter table ta1 rename to ta0;
     
    3---------------添加一个字段------------------------------------
    Alter table 表名 add column 字段的名称 varchar(20) not null default 1 comment '对该字段的解释' after 其他字段
    解释:after,新增的字段在after字段名字段后面,有排序的作用。
     
    4---------------删除一个字段------------------------------------
    alter table 表名 drop 字段名
     
    5---------------删除数据/库(只删除数据结构不删除-----drop是整个表会删除,包括表的数据和表的结构。truncate是先删除整个表,在建立起表的结构,数据会丢失)------------------------------------
    drop database 【数据库的名字】;
    truncate 表名  //删除表中数据。【释放空间,id会重置】
    delete from 表名 【一行一行的删除数据,不释放空间,可以发现再次添加数据数据的id是不断的叠加的】
     
    6---------------修改字段名称------------------------------------
    alter table 表名 change 旧字段 新字段 varchar(20)
    demo:
       alter table ta0 change names name varchar(20);
     
    7---------------修改字段类型------------------------------------
    alter table 表名 modify 字段 字段的新类型
    demo:
       alter table ta0 modify uname int;
     
    8----------------查询语句-----------------------------------
       select * from 表名 where +条件
     
    9----------------插入语句-----------------------------------
    (1)    insert into 表名 values (字段);
                   demo:
                   insert into ta1 values(1,'2');
    (2)  insert into  表名(字段名) values (对应的值);
                   demo:
                   insert into ta1 (id,username) values (2,'散');
     
    10----------------更新语句-----------------------------------
      update 表名 set 字段名 = 值
      demo:update ta1 set username='4';
     
     
     
     
     
  • 相关阅读:
    int 和 Integer 有什么区别?
    内部类可以引用它的外部类的成员吗?有没有什么限制?
    为什么Java不支持运算符重载?
    生命周期内create和mounted的区别?
    JSP有哪些动作?分别是什么?
    vue解除双向绑定?
    实现一个函数功能:sum(1,2,3,4..n)转化为 sum(1)(2)(3)(4)…(n)?
    新旧生命周期?
    vue异步组件?
    XML文档约束有哪几种?有什么区别?
  • 原文地址:https://www.cnblogs.com/taotingkai/p/6178538.html
Copyright © 2011-2022 走看看