Oracle百问百答(一)

Oracle百问百答(一)

 

01.如何查看oracle的版本信息?

02.如何查看系统被锁的事务信息?

03.怎么获取有哪些用户在使用数据库?

04. 数据表中的字段最大数是多少?

表或视图中的最大列数为 1000

05. 怎样查得数据库的SID ?

select name from v$database;,也可以直接查看 init.ora文件

06. 如何查询表空间信息?

 

07. 如何统计两个表的记录总数?

 

08.如何获取系统的当前日期,若天数大于15,显示1,否则显示0

09. drop userdrop user cascade有什么区别?

drop user :仅仅是删除用户;drop user ×× cascade :会删除此用户名下的所有表和视图。

10数据库表中没有设置级联删除.怎样用SQL语句实现,例如:
EMP
表中有字段DEPT_NO是外键
POS
表中有字段DEPT_NO是外键
DEPT
表中有字段DEPT_NO,
如何实现删除DEPT表中数据时将EMP,POS表中的相关数据也删除?

方法一:触发器解决
create or replace trigger delete_dept
before delete on DEPT
for each row
begin
 
delete from EMP where DEPT_NO = :old.DEPT_NO;
 delete from POS where DEPT_NO = :old.DEPT_NO;
end;

方法二:修改从表的外键设置,改为“on delete cascade”模式

  a)先查询出EMP表和POS表中外键的名称(如果已知道外键名,这一步可以省略)
 
select CONSTRAINT_NAME,TABLE_NAME from user_constraints where CONSTRAINT_TYPE ='R' and TABLE_NAME in('EMP','POS');
 b)
删除EMP表和POS表上的外键后重新建立允许级联删除的外键模式
  
alter table EMP drop constraint 外键名;
  
alter table POS drop constraint
外键名;
  
alter table EMP add constraint
外键名 foreign key(DEPT_NO) references DEPT(DEPT_NO) on delete cascade;
  
alter table POS add constraint
外键名 foreign key(DEPT_NO) references DEPT(DEPT_NO) on delete cascade;

 

 

 

posted on 2013-09-09 20:47  you Richer  阅读(229)  评论(0编辑  收藏  举报