zoukankan      html  css  js  c++  java
  • DB总结1

    DBA  重构 data  new york   committee   cobol codasyl  journal

    DDL  DML    关系演算  域关系演算语言(QBE)  元祖关系演算语言(ALPHA)  

    查询语言其实本质是逻辑语言  聚集函数(内置函数)  象集

    除运算(一定有相同的列)的结果是被除关系的某一行值(有时候是不能随便除)

    SQL语句是大小写模糊的,并且分号模糊         模式包含数据库

    为用户定义一个模式              约束条件在数据字典里

    Create   schema”S-T”   authorization niu;

    Drop  schema”S-T” <cascade|restrict>

                      级联(全部删除)    限制(模式为空时删除)

    Create   table  Student

                          (Sname  char(9)  primary key,

                          SAge    smallint,

                          );

    Numeric定点数     decimal

    Foreign  key  Cpno  references  course(Cno) 外码主键

    主码超过一个属性为主键时,必须用表级完整性约束定义

    Create  table”s-t”.student(              );

    修改表:

    Alter  tbale  student

         Add  brithday  date

         Drop <完整性约束名>

         Alter  column  sage  int

    Drop  table   student cascade;

    建立索引: create (unique  cluster聚族索引)index  index1

               On student( Sage 1

                         Sname 2

                                      );

    删除索引:drop index index1;

    聚族索引:就是索引项的顺序与表中记录一致

    索引建立在多列或是一列    ASC升    DEFC降

    默认为ASC  

    Create   unique index Scno on  SC(Sno  ASC,Cno DESC);

    查询:

    Select  all|distinct   *****

    From  student **  **

    Where   ***

    Group by 列   hacing **

    Order by  列   ASC|DESC;

    Select *

    Lower小写

    可以加入字符串 select  Sname  ‘yourname:’ Sname

    Select  distinct  Sno  就是取消重复的

    <>  不等于  like    where Sage<20

    Where   Butween**and **    not between**and**

    Where  Sage  ( not)  in(‘11’,’33’)

    Not like ‘ ***’ escape ‘***’

    %(通配符)——任意长度   _ 代表任意单个长度

    Where Cname like’%牛’

    Escape ‘’  转换字符

    Where Cname like ‘ db\_Design ‘  escape’’

    空值查询   where  grade is (not)null

    多重查询用and

    Group by grade,Sage  DESC

    聚集函数:  count(distinct|all*)

                Count(distinct|all  Sage)

                Sum(distinct|all  Sage)

                Avg(distinct|all  Sage)

                Max(distinct|all  Sage)

                Min(distinct|all  Sage)     注意:都是无重复

    Select  Cno,count(Sno)

    From SC

    Group by Cno;按Cno分组

    Having count(*)>3; 是分组聚集运算之后再选择

    连接查询(多表查询)  

    Select  first.Cno,second.CPno   自身连接

    左外连接:

    From  student left( outer join) SC on(student.Sno=SC.Sno)  就不需要where

    子查询里一般用in =  或是>=等

    Select Sno,Cno

    From SC x

    Where Grade >=(select avg(Grade)

                  From SC y

                   Where y.Sno=x.Sno);

    子查询里的 Any  all  

    Where Sage <all    (not)(exists)(返回真假)

              (select Sage

               Prom student

              Where   Sdept=’CS’)

            And Sdept<>’CS’;

    结果之间的union  intersect交   except差

    数据插入:

    Insert

    Into student ( 列 列 列           )

    Value(        1   2  2)(或者这个可以是子查询的结果)

    修改:

    Updata  student

    Set      Sage=22

    Where ****

    删除:

    Delete

    From student

    Where ***

    定义视图:

    Create view student (列 列 列 )

    AS 子查询

    (With check  option)

     删除视图:

    Drop view student  cascade;

    视图其他的和表一样,视图是表的镜像,可以灵活改变

                                                         2017 4.11  中国 兰州

  • 相关阅读:
    SDUT 1299 最长上升子序列
    HDU 1754 I Hate It
    SDUT 2080 最长公共子序列问题
    HDU 1102 Constructing Roads HDU1863 畅通工程
    HDU 1166 敌兵布阵
    HDU 1874 畅通工程续
    准备翻译Windows 8 动手实验系列教程
    Windows 8 动手实验系列教程 简介
    一起学Windows phone7开发(十九. Windows phone7发布)
    一起学Windows phone7(十六. windows phone 7 developer tool RTM 发布)
  • 原文地址:https://www.cnblogs.com/niu3/p/9352054.html
Copyright © 2011-2022 走看看