zoukankan      html  css  js  c++  java
  • mysql 基础

    show databases;查看所有数据库

    create database 库名; 创建数据库

    use 库名; 进入数据库

    show tables; 查看数据库所有表

    describe 表名;查看表结构

    drop database 库名;删除数据库

    drop table表名 ;删除表

    ///////////////////////////////////////////////////////

    创建表lcs

    create table lcs (
      lcsId int primary key auto_increment,
      lcsName varchar(20),
      lcsSex int,
      lcsPhone long
    );

    describe lcs;查看表结构

    1.--alter table 表名 rename/drop/change/add...;alter增、删、改表中元素,改表名

    1.1.alter table lcs rename lcs newLcs;更改表名为newLcs

    1.2.alter table lcs add lcsAddress varchar(50);

    1.3.alter table lcs drop lcsPhone;删除表元素

    1.4.alter table lcs change lcsName lcsTitle text;修改表元素和类型为 lcsTitle text

     ////////////////////////////////////////////////////////////

    mysql表中元素类型:int(主键)  varchar(名字和其它)  text(文字)  dateTime(时间)  date  long  double......

    2.--CRUD: Create   Read  Update  Delete

    C: --Insert into tableName (tableElement ……) values (newTableElementValure ……);每次插入数据都会插入新的一行数据/批量插入

    2.1.insert into lcs(lcsName,lcsSex,lcsPhone) values('hero',1,18277198);按元素对应写元素值,主键自动增长

    2.2.insert into lcs values(null,'hanson',1,365432);按元素顺序对应写所有元素值

    2.3.insert into lcs(lcsName) values("man"); varchar字符类型要单引号

    2.4.insert into lcs values (null,'boy',1,158773),(null,'girl',0,1587623);可同时插入多个

    -------------------------------------------------------------------------------------------------------------------------

    R:--select  *  from  tablename;查询指定表中所有的数据

    2.5.select * from lcs;

    2.6.select lcsId,lcsName from lcs;

    2.7.select lcsName as 'usersName' , lcsSex as 'usersSex' from lcs;

    2.8.select * from lcs where lcsName='hero';

    2.9.select * from lcs where lcsName!='hero';

    2.10.select * from lcs where lcsName <> 'hero';

    U:--update tableName set tableElement = newTableElement …… where statement :更改元素数据值,全部更改newTableElement的值

    2.11.update lcs set lcsPhone =18277111111;所有lcsPhone的数据值改为18277111111

    2.12.update lcs set lcsPhone =18269555555 where lcsSex=0;条件 where lcsSex=0时,所有lcsPhone 的数据值改为18269555555

    2.13.update lcs set lcsPhone =15017718514 where lcsName='hero';

    2.14.update lcs set lcsPhone =15245287817,lcsName='man' where lcsId = 2;

    D:--Delete from tableName where statement;删除元素值

    delete from lcs;删除lcs表中所有元素的数据(元素值)

    delete from lcs where lcsName='man';删除元素lcsName='man'的所有数据

    工作如同河川,自闲暇的深海觅得圆满。
  • 相关阅读:
    php程序员的弱点
    php cli 模式下执行文件,require 加载路径错误
    第一次!
    IO流(一)之IO流综述
    异常和错误
    Comparable与Comparator比较分析
    Collection与Map学习笔记(三)
    两个对象比较
    Collection与Map学习笔记(二)
    包装类、及装箱和拆箱
  • 原文地址:https://www.cnblogs.com/phpli/p/4518380.html
Copyright © 2011-2022 走看看