使用索引:
CREATE INDEX INDSN ON STUDENT(SNAME);
CREATE INDEX SESAIND ON STUDENT(SAGE,SSEX);
SELECT index_name FROM USER_INDEXES WHERE table_name =‘表名’;
--查看索引
查看索引的步骤:
analyze table 表名 compute statistics;
--查看索引分析
SET autotrace on explain;
--打开计划分析
执行SELECT查询进行验证
DROP INDEX INDSN;
--删除索引
declare
vtoday date;
vcnt number(8,0):=1000000;
begin
select sysdate into vtoday from dual;
for i in 1..vcnt loop
insert into emp1(id,name,sex,birth,phone) values(i,'name'||i,mod(i,2),vtoday-i,'phone'||i);
if mod(i,100)=0 then commit;
end if;
end loop;
end;
/
--向表中插入1000000行数据
视图:
GRANT CREATE VIEW to scott;
--先sysdba权限登录管理员帐号,授权给scott
CREATE VIEW SV1 AS SELECT SNO,SNAME FROM STUDENT;
CREATE VIEW SV1(学号,姓名) AS SELECT SNO,SNAME FROM STUDENT;
CREATE VIEW S_G (Sno,Gavg)
AS SELECT Sno,AVG(Grade) FROM SC
GROUP BY Sno;
--创建复杂视图
CREATE VIEW SAGE_Stu
AS SELECT Sno,Sname,Sage FROM Student
WHERE Sage>19
WITH CHECK OPTION;
CREATE VIEW SV2
AS SELECT SNO,SNAME,SAGE FROM
WHERE SDEPT=‘信息科学与工程学院’
WITH READ ONLY;
--只读视图
SELECT VIEW_NAME ,TEXT FROM USER_VIEWS;
--查询当前用户的视图及定义
DESCRIBE 视图名;
--查询视图的列
SELECT 视图列名[,……] FROM 视图名;
--查询视图数据
视图的更新,指对视图进行insert,update,DELETE操作,实际上是对基本表的更新。
UPDATE S_G SET Gavg=90 WHERE Sno= ‘001’;
DROP VIEW 视图名;
--删除视图