zoukankan      html  css  js  c++  java
  • mysql

    ER模型 --- 关系模型 --- 二维表

      1. char [ 固定 删除尾部空格 ]

      2. varchar [ 可变 不删除尾部空格 ]

    char varchar 区别

    create table test1(c char(4),v varchar(4));

    insert into test1 values('a   ','b   ');

    select concat(c,'#'), concat(v,'#') from test1; 

      3. blob [ Binary Large of Object ] 电影
      4. text [ 文本 ] 
      5. date

      6. datetime


      

    alter

    add modify drop

    show  variables like 'character%'; // 查看所有的字符编码

    插入时 中文问题 :  

    set character_set_client = gb2312;

    显示时 中文问题 : 

    set character_set_results = gb2312;

    delete 删除记录

    drop 删除表

    delete truncate最大区别在执行性能,使用truncate可以将效率提高近一倍。


    数据库的备份和还原

    备份:mysqldump -uroot -p mydb2 > c:\db2.sql [windows]

    还原:source c:\db2.sql; [sql]

    mysql -uroot -p mydb2 < c:\db2.sql [windows]

    select :

    select distinct deptname from student; // 唯一性

    select name 姓名, english 英语成绩 from student; //别名作为显示

    select name, english+10 from student; //算术表达式

    select name 姓名, match+chinese+english 总分 from student where 总分 > 200; //别名代替复杂表达式

    select name, english from student where english between 80 and 90; //between and 语句

    select name, english from student where english in (84, 85, 86); //in 语句 

    select name, english from student where english not in (84, 85, 86); //not in 语句 

    select * from student where name like '张%' ; //like语句

    select * from student where name like '张_'; //like语句 占位符占据一个英文或者中文


    默认 升序 排序

    select * from student order by match+chinese+english desc; //默认为 升序 指定为 降序

    select name,math+english+chinese 总分 from student order by 2 desc; // 索引号

    select name,math+english+chinese 总分 from student order by 总分 desc; // 别名


    合计函数

    count 

    select  count(*) from student where math > 90;

    sum

    select sum(math),sum(english),sum(chinese) from student;

    select sum(math+english+chinese) from student;

    select sum(chinese)/count(*) from student;

    avg

    select avg(chinese) from student;

    max

    select max(math), min(math) from student;

    group by

    select deptname, sum(math+chinese+english) from student group by deptname;

    having (可以使用合计函数,作用于分组之后筛选)

    select deptname, sum(math+chinese+english) from student group by deptname having sum(math+chinese+english) > 200;


    日期类函数 

    now() 年月日时分秒

    insert into employee values(... ... ... ... , now(), ...); //插入当前时间 (mysql 写法)

    insert into employee values(... ... ... ... , sysdate, ...); //插入当前时间  (oracle 写法)

    addtime(date, time_interval) 年月日时分秒

    select  addtime(now(),'01:00:00');

    current_date() 年月日

    select current_date();

    date(datetime) 年月日

    select date(now());

    current_time() 时分秒

    select current_time();

    YEAR|MONTH|DAY(datetime) 单独年月日

    select YEAR(now()) ;

    字符串类 数学类

    完整性

    主键约束 ( primary key ) : 非空且不重复 [ 定义自动增长 mysql中用auto_increment oracle中用序列]

    唯一性约束 ( unique )

    非空约束 ( not null ) 

    外键约束 ( foreign key ) : constraint ordersid_FK foreign key(当前表的某列) references(被引用表的某列) 特别注意这种父子表关系

    多表查询

    1. 笛卡尔集

    举例:select student.name

    from student,grade (如果没有where条件字句 查询结果为两表的笛卡尔集)

    where grade.gradeName = '01'

    and grade.gradeID=student. gradeID;

    2. 表之间的关系 一对一 一对多 多对一 (java 类 写法 父对象中包含子对象集)

  • 相关阅读:
    Insufficient parameters supplied to the command
    helloworld program of Linden Scripting Language
    使用DEV控件开发的小软件,单词查询及单词浏览
    SqlBulkCopy基本使用
    .NET3.0+中使软件发出声音[整理篇]
    Quick Hack for Setting the Row Height of a ListViewItem
    WCF返回JSON及EXT调用WCF
    拖动PictureBox 代码片断
    WCF配置工具及服务调试工具
    为指定的XML文件生成类并反序列化
  • 原文地址:https://www.cnblogs.com/Knuth/p/2662076.html
Copyright © 2011-2022 走看看