orcale使用记录

创建表空间sgwood:
create tablespace sgwood datafile 'H:\oracle\product\10.2.0\oradata\orcl\sgwood.dbf' size 200m autoextend on next 10m maxsize unlimited;
建表admin_emp:
create table admin_emp (
empno NUMBER(5) PRIMARY KEY,
ename VARCHAR(15) NOT NULL,
ssn NUMBER(9) ,
job VARCHAR2(10),
mgr NUMBER(5),
hiredate DATE DEFAULT (sysdate),
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(3) NOT NULL
)
alter table system.admin_emp add
(location varchar2(80),
tel varchar2(10));

alter table admin_emp
rename column ssn to ssno;
alter table admin_emp
set unused(comm);
SQL> select * from all_unused_col_tabs;

OWNER                          TABLE_NAME                          COUNT
------------------------------ ------------------------------ ----------
SYSTEM                         ADMIN_EMP                               1
//改变表存储
alter table system.admin_emp move
storage (initial 20K
next 40K
maxextents 20
pctincrease 0);

tablespace sgwood
STORAGE (INITIAL 50K);
建序列emp_sequence:
create sequence emp_sequence
increment by 1
start with 1
nomaxvalue
nocycle
cache 10;
alter sequence emp_sequence
increment by 10
maxvalue 1000
cycle
cache 20;
insert into admin_emp(empno,ename,deptno) values(emp_sequence.NEXTVAL,'sgwood',120);
insert into admin_emp(empno,ename,deptno) values(emp_sequence.NEXTVAL,'sgwood',emp_sequence.CURRVAL);
insert into admin_emp(empno,ename,deptno) values(emp_sequence.CURRVAL,'sgwood',emp_sequence.NEXTVAL);
SQL> select empno,ename,deptno from admin_emp ;

     EMPNO ENAME               DEPTNO
---------- --------------- ----------
         1 2                        3
         2 sgwood                 120
         3 sgwood                 120
         4 sgwood                 120
         5 sgwood                 120
         6 sgwood                 120

已选择6行。

创建视图sales_staff:
create view sales_staff as
select empno,ename,deptno
from admin_emp
where  deptno=120
with check option constraint sales_staff_cnst;
insert into sales_staff values(7788,'OSTER',120); OK!
insert into sales_staff values(7788,'OSTER',12);
select * from sales_staff;

select view_name,text_length,text from dba_views where view_name='SALES_STAFF';

select column_name,data_type,data_length,last_analyzed from dba_tab_columns where owner='SCOTT' and TABLE_name='EMP';

你可能感兴趣的:(oracle,sql,cache)