PL / SQL tables and views (study notes)

A: Table

5.1; the establishment of a table

Create a table with PL / SQL

CREATE TABLE NEW_DEPT(
DEPTNO NUMBER(2),
DNAME CHAR(6),
LOC CHAR(12)
);

1: must have a wide number;

2: punctuation, it must be in English;

3; last line of data should be no punctuation;

ALTER TABLE NEW_DEPT
MODIFY DNAME CHAR(20)

4: must have administrator privileges possible to build this table

Define table and column names to meet certain rules, both the table name and the first letter of the column name must be in English letters, characters that follow can be letters or numbers, and $, #, and other symbols, but not a comma, name length, not more than 30 characters.

Data type generally CHAR (character); NUMBER (numeric); DATE (date type); a LONG (char length); the RAW (binary type); CHAR (N) represents the character length; NUMBER (n, d) to define the length and number of decimal places entered numerical data;

In some cases, the user data may not be allowed to empty, it may be later combined with NOT NULL;

5.2: Modify table

An increase

ALTER NEW_DEPT
ADD(HEADCNT NUMBER(2))

Modify the data length (from 10 into 20)

ALTER TABLE NEW_DEPT
MODIFY DNAME CHAR(20)

5.3 Delete table

DROP TABLE NEW_DEPT

II: View

The actual view is a virtual table; the data which is extracted by the other tables and views. The view is based table called a base table;

It provides an additional level of security

The complexity of the hidden data

We can provide the means to transform the column name, without really changing the definition of a base table

Since the view does not contain data, in addition to a rear view of the name, the table should also be noted how to retrieve data from the existing configuration in the view.

CREATE VIEW MANAGER AS 
SELECT ENAME,JOB,SAL 
FROM NEW_DEPT
WHERE JOB='MANAGER'

At the time of establishment of view, you can not use the ORDER BY clause to specify the data source view. By default, the column name and column names in the view of the table as the original group;

 The following is the column names have changed

CREATE VIEW MYDEPT
(PERSON,TITLE,SALARY)
AS SELECT ENAME,JOB,SAL 
FROM NEW_DEPT
WHERE JOB='MANAGER'

Beyond the allowed range can view the selected row


CREATE VIEW MANAGER 
(PERSON,TITLE,SALARY)
AS SELECT ENAME,JOB,SAL 
FROM NEW_DEPT
WHERE JOB='MANAGER'
WITH CHECK OPTION

Delete view

DROP VIEW VIEW_NAME

Third, the replication of tables and views

Copy table

CREATE TABLE EMP2
AS SELECT *
FROM EMP

Copy view

CREATE VIEW NEW_DEPT20
AS SELECT * FROM DEPT20

 

 

reference

https://www.cnblogs.com/arxive/p/6139465.html

http://wf.tedu.cn/news/340785.html

Published 153 original articles · won praise 15 · Views 150,000 +

Guess you like

Origin blog.csdn.net/beyond911/article/details/103840118