zoukankan      html  css  js  c++  java
  • Oracle SQL Lesson (11)

    schema(模式)
    一个用户下一组对象的集合,一般与用户名一致。

    视图

    CREATE [OR REPLACE] [FORCE|NOFORCE] VIEW view
    [(alias[, alias]...)]
    AS subquery
    [WITH CHECK OPTION [CONSTRAINT constraint]]
    [WITH READ ONLY [CONSTRAINT constraint]];
    create view empvu80 as select employee_id, last_name, salary from employees where department_id = 80;
    desc empvu80;
    grant create view to scott;
    create view v1 as select * from dept;
    select text from user_views where view_name='V1';

    使用列别名

    CREATE VIEW salvu50 AS SELECT employee_id ID_NUMBER, last_name NAME, salary*12 ANN_SALARY FROM employees WHERE department_id = 50;

    复杂视图的操作限制
    如果视图包含如下项,则不能删除行
    -Group functions
    -A GROUP BY clause
    -The DISTINCT keyword
    -The pseudocolumn ROWNUM keyword

    如果视图包含如下项,则不能修改数据
    -Group functions
    -A GROUP BY clause
    -The DISTINCT keyword
    -The pseudocolumn ROWNUM keyword
    -Columns defined by expressions

    如果视图包含如下项,则不能增加数据
    -Group functions
    -A GROUP BY clause
    -The DISTINCT keyword
    -The pseudocolumn ROWNUM keyword
    -Columns defined by expressions
    -NOT NULL columns in the base tables that are not selected by the view

    CREATE OR REPLACE VIEW empvu20 AS SELECT * FROM employees WHERE department_id = 20 WITH CHECK OPTION CONSTRAINT empvu20_ck ;
    
    CREATE OR REPLACE VIEW empvu10(employee_number, employee_name, job_title) AS SELECT employee_id, last_name, job_id FROM employees WHERE department_id = 10 WITH READ ONLY ;
    
    create table d as select * from dept;
    create view v1 as select * from d where deptno=40 with check option;
    insert into v1 values(50,'EDU','CHINA');
    insert into v1 values(40,'EDU','CHINA');
    
    ALTER VIEW V1 READ ONLY;
    create or replace view v1 as select * from emp;

    使用序列(sequence)

    CREATE SEQUENCE sequence
    [INCREMENT BY n]
    [START WITH n]
    [{MAXVALUE n | NOMAXVALUE}]
    [{MINVALUE n | NOMINVALUE}]
    [{CYCLE | NOCYCLE}]
    [{CACHE n | NOCACHE}];

    NEXTVAL must be issued for that sequence before CURRVAL contains a value.
    第一次必须使用NEXTVAL.

    CREATE SEQUENCE dept_deptid_seq INCREMENT BY 10 START WITH 120 MAXVALUE 9999 NOCACHE NOCYCLE;
    
    ALTER SEQUENCE dept_deptid_seq INCREMENT BY 20 MAXVALUE 999999 NOCACHE NOCYCLE;
    
    DROP SEQUENCE dept_deptid_seq;

    使用索引
    B树索引,位图索引
    海量数据中查询少量数据。

    CREATE [UNIQUE][BITMAP]INDEX index
    ON table (column[, column]...);
    CREATE INDEX emp_last_name_idx ON employees(last_name);
    
    DROP INDEX emp_last_name_idx;

    Index Creation Guidelines

    建议创建索引
    A column contains a wide range of values
    A column contains a large number of null values
    One or more columns are frequently used together in a where clause or a join condition
    The table is large and most queries are expected to retrieve less than 2% to 4% of the rows in the table

    不建议创建索引
    The columns are not often used as a condition in the query
    The table is small or most queries are expected to retrieve more than 2% to 4% of the rows in the table
    The table is updated frequently
    The indexed columns are referenced as part of an expression

    同义词

    CREATE [PUBLIC] SYNONYM synonym
    FOR object;

    只有sysdba才可以创建公共同义词。

    conn scott/tiger;
    create synonym e for emp;
    select * from e;
    
    conn / as sysdba
    create public synonym e1 for scott.emp;
    grant select on e1 to public;
    
    conn hr/hr;
    select * from e1;
    
    conn / as sysdba;
    select index_name from user_indexex where table_name='E';

    自动创建的索引。

  • 相关阅读:
    vue 同页面不同参数
    vue的data用到this问题
    vue轮播,不是只有左右切换的,还有只切换src的
    vue页面高度填充,不出现滚动条
    WdatePicker做出onchange效果
    总结最近移动端遇到的坑(auto-size + zepto)
    react
    ES6-set && 数组剔重
    [置顶] Jquery easyui+Jsonp+asp.net+翻页 事件版
    扩展Jquery easyui的validator插件
  • 原文地址:https://www.cnblogs.com/thlzhf/p/3405044.html
Copyright © 2011-2022 走看看