Oracle-DDL 2- & view index

DDL- data definition statements:

 Second, the view

- View (View), the data itself is not stored, is stored in a query
- the view is identical to the operation of the operation query statement in the source data
- less storage space occupied views, you can quickly specific data access and manipulate
- the view is mainly used for the same data, create different views to separate access and operations
- to create the appropriate view can simplify query
- need the appropriate permissions to create a view

/ *
The Create or replace [name] view view
[(column name 1, column names 2, ......)]
AS
the SELECT ......
[with read only];

or replace if you do not write, create view name already exists will complain
if you write on or replace the view with the same name will be replaced

with read only expressed the view can only view, not modify data
* /

- scott user with an administrator to create a view given permission to
GRANT CREATE VIEW TO scott;

1. The distinction between rights
--emp table for different employees and jobs, you can access and manipulate the data is not the same
--boss hr and can view and modify information for all employees, directly emp
- managers can view and modify the department employee information
- ordinary people can only view their own information, can not be modified

- for managers and employees to create different views of distinction

- department managers view
the CREATE VIEW v_dept20
AS
the SELECT * the FROM emp
the WHERE deptno = 20;

- a view consistent with the operation of the operation to the table
SELECT * FROM v_dept20;

- modification of data in a view equivalent to the modification of the source table data in
the UPDATE v_dept20
the SET SAL = 1500
the WHERE ename = 'SMITH';

SELECT * FROM emp;

- view of the general staff of
the CREATE VIEW v_7369
AS
the SELECT empno, ename, the Job, SAL, the FROM deptno emp
the WHERE empno = 7369
the WITH the READ ONLY;

SELECT * FROM v_7369;

UPDATE v_7369
SET sal = 2000;

 

2. Simplified query

- Number of employees Query research department
1) sub-query
the SELECT COUNT (*) the FROM emp
the WHERE deptno =
(the SELECT deptno the FROM the dept the WHERE DNAME = 'RESEARCH');

2)多表查询
SELECT COUNT(e.empno)
FROM emp e,dept d
WHERE e.deptno = d.deptno
AND d.dname = 'RESEARCH';

3) view
- if some data relationships between tables very close, often as a condition for each query
- can be prepared in advance corresponding view, query data from a view in
the CREATE VIEW emp_dept
AS
the SELECT * E, d.deptno dno. , d.dname, d.loc
the FROM EMP E, D Dept
the WHERE e.deptno (+) = d.deptno;

SELECT * FROM emp_dept;

- Number of employees Query research department of
the SELECT COUNT (*) the FROM emp_dept
the WHERE DNAME = 'RESEARCH';


Third, the index

- Index (index) to create a column in the data table index can improve query performance
- each row in the data table stored location has a rowid
the SELECT ename, the ROWID the FROM emp;
- the index data and rowid the correspondence relationship, direct access by rowid storage location data
- often as a query to create a column index to improve query efficiency

1.B tree index
- the Create index index name on table name (column name);
the CREATE INDEX index1 ON emp (ename);

- Make sure the index creation
SELECT * FROM user_indexes;

- the index does not need to use, when to use the query conditions in the relevant columns, indexes automatically improve query efficiency
- when data changes in the table, the index will automatically update the relevant data associated with them

When --b tree index column data applicable to a large number of different data
- a column when a lot of repeated data, not suitable for b-tree indexes, bitmap index should be used

2. Bitmap Index
- bitmap index numbers used to store a binary key value of a particular row
- Create Bitmap Index Name on index table (column names);
the CREATE the BITMAP the INDEX index2 the ON EMP (DEPTNO);

 

Guess you like

Origin www.cnblogs.com/JodieRao/p/11358213.html