oracle 小複習總結

oracle 複習總結

 1、以SYS身份登錄,觀察數據庫運行模式,如果運行在非歸檔模式下,請切換至歸檔模式下

archive log list;
mount:alter database archivelog;
 
2、用SYS查看HR的狀態,如果是鎖定,則解鎖並重設密碼
select * from dba_users where username='HR';
 
3、創建表空間inventory,數據文件inventory01.dbf,大小10M
create tablespace inventory datafile 'k:\dbf\inventory01.dbf' size 10m;
 
4、修改inventory01.dbf的大小爲20m
alter database datafile 11(文件號) resize 30m;
 
5、用hr登錄查看擁有的角色,用sys查HR擁有的角色
hr:select * from user_role_privs;
sys:select * from dba_role_privs where grantee='HR';
 
6、查看CONNECT角色包裝的權限
select * from dba_sys_privs where grantee='CONNECT';
 
7、查看hr的默認表空間,用hr創建表hrtest1到inventory表空間上。
create table hrtest1(int id) tablespace inventory;
 
8、查看hr的系統權限。
select * from dba_sys_privs where grantee='HR';
 
9、回收hr的unlimited tablespace權限
 revoke unlimited tablespace from hr;
 
10、用hr創建表hrtest2到inventory表空間上。(觀察結果)
create table hrtest2(int id) tablespace inventory;(報錯)
 
11、爲hr在inventory表空間上分配使用限額10m
 alter user hr quota 5m on inventory;
 
12、用hr創建表hrtest2到inventory表空間上。
create table hrtest2(int id) tablespace inventory;
 
13、查看hr在inventory表空間上創建了哪些表。
select * from user_tables where tablespace_name='INVENTORY';
 
14、在hrtest1中錄入100條測試數據。
declare
  i int:=1; 
begin
  for i in 1..100 loop
     insert into hrtest1 values(i);
  end loop;
  commit;
end;
 
15、刪除前10條。
delete from hrtest1 where id in(
select id from hrtest1 where rownum<=10)
 
16、爲表添加一列testTime date型
alter table hrtest1 add testTime date;
 
18、更新第5列至第10列的testTime爲2011-8-20 11:30:20
update hrtest1 set testTime=to_date('2011-08-20 11:20:30','yyyy-mm-dd hh24:mi:ss') where id in
(select id from (select rownum r,id,testTime from hrtest1) tmp where r>=5 and r<=10);
 
19、刪除ID號爲100的記錄,並提交(記錄時間)
delete from hrtest1 where id=100; 
commit;
 
20、閃回到未刪除ID號爲100的記錄前的狀態
alter table hrtest1 enable row movement;
flashback table hrtest1 to timestamp to_timestamp('20110825 10:48:40','yyyymmdd hh24:mi:ss');
 
21、刪除表hrtest1,檢查回收站
drop table hrtest1;
select * from user_recyclebin;(show recyclebin;)
 
22、從回收站閃回hrtest1表
flashback table hrtest1 to before drop;
 
23、手工備份inventory表空間(聯機狀態)
alter tablespace inventory begin backup;
host copy k:\dbf\INVENTORY01.DBF k:\bak\inven01.dbf;
alter tablespace inventory end backup;
 
查看歸檔日誌列表,並強制切換當前在線日誌的內容至歸檔日誌中。
select * from v$archived_log;
alter system switch logfile;
 
24、在hrtest1表中插入一條ID爲101,testTime爲當前時間的記錄,並提交。
insert into hrtest1 values(101,sysdate);
commit;
 
25、關閉數據庫,刪除磁盤上的inventory01.dbf文件後啓動數據庫。
shutdown immediate
刪除OS文件。
startup
 
26、查看哪些文件需要恢復。使這些文件單獨脫機。並查看需要哪些日誌。
select * from v$recover_file;(mount下可用)
select * from v$recovery_log;(若日誌信息很少,則無顯示,但並不是不需要)
alter database datafile 12 offline;
alter database open;
 
27、恢復缺失文件。
host copy  k:\bak\inven01.dbf k:\dbf\INVENTORY01.DBF;
recover datafile 12;
alter database datafile 12 online;
 
28、使用RMAN備份inventory表空間,分配兩個通道
run
{
 allocate channel c1 type disk;
 allocate channel c2 type disk;
 backup tablespace inventory;
 release channel c1;
 release channel c2;
}
 
29、使用RMAN備份inventory表空間(壓縮方式),分配兩個通道
run
{
 allocate channel c1 type disk;
 allocate channel c2 type disk;
 backup as compressed backupset tablespace inventory;
 release channel c1;
 release channel c2;
}
 
30、向hrtest1表中插入一條ID爲102的記錄並提交。然後關閉數據庫。
insert into hrtest1 values(102,sysdate);
commit;
shutdown immediate;
 
31、刪除磁盤上的inventory01.dbf文件後啓動數據庫。重複第26題。
 
32、利用RMAN恢復缺失文件。
run
{
allocate channel c1 type disk;
restore tablespace inventory;
recover tablespace inventory;
release channel c1;
}
 
33、修改RMAN配置爲兩個通道。
configure device type disk parallelism 2;
 
34、查看shared pool以及database buffer cache的大小,調整。
 alter system set shared_pool_size=70m scope=both;
 alter system set db_cache_size=34m scope=both;
(alter system flush shared_pool;)
 
35、查看hr的使用限額(在其可使用的表空間上)
select * from dba_ts_quotas where username='HR';
 
36、查看HR在默認表空間上創建的表
select * from user_tables;
 
37、在默認表空間上的表test2
create table test2(tid int,tname varchar2(10));
 
38、添加主鍵約束
alter table test2 add constraint PK_TID primary key (tid);
 
38、錄入兩條數據
insert into test2 values(1,'aa');
insert into test2 values(2,'aa');
commit;
 
39、添加唯一性約束在列tname上。
alter table tt add constraint UK_TNAME UNIQUE(tname) DEFERRABLE ENABLE NOVALIDATE;
 
40、擴展列tname的長度爲20個字節。
alter table tt modify tname varchar2(20);
 
41、hr授權給scott查詢自己的表departments的權限。
grant select on departments to scott;
 
42、用scott用戶查hr的departments表。
select * from hr.departments;
 
43、在scott下創建同義詞(爲departments建同義詞depts)
create synonym depts for hr.departments;
 
44、複製表departments表
create table dept2 as select * from departments;
 
45、導出dept2的數據後,用快速方式刪除表中數據,再進行導入。
快速刪除表數據:truncate table dept2;(ddl操作不能回滾)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章