当前位置:Gxlcms > 数据库问题 > oracle查看用户信息

oracle查看用户信息

时间:2021-07-01 10:21:17 帮助过:14人阅读

9、Oracle删除指定用户所有表的方法
select ‘Drop table ‘||table_name||‘;‘ from all_tables
where owner=‘要删除的用户名(注意要大写)‘;
10、删除用户
drop user user_name cascade;
如:drop user SMCHANNEL CASCADE
11、获取当前用户下所有的表:select table_name from user_tables;
12、删除某用户下所有的表数据: select ‘truncate table ‘ || table_name from user_tables;
13、禁止外键
ORACLE数据库中的外键约束名都在表user_constraints中可以查到。其中constraint_type=‘R‘表示是外键约束。
启用外键约束的命令为:alter table table_name enable constraint constraint_name 
禁用外键约束的命令为:alter table table_name disable constraint constraint_name
然后再用SQL查出数据库中所以外键的约束名:
select ‘alter table ‘||table_name||‘ enable constraint ‘||constraint_name||‘;‘ from user_constraints where constraint_type=‘R‘
select ‘alter table ‘||table_name||‘ disable constraint ‘||constraint_name||‘;‘ from user_constraints where constraint_type=‘R‘
14、ORACLE禁用/启用外键和触发器
--启用脚本
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select ‘ALTER TABLE ‘||TABLE_NAME||‘ ENABLE CONSTRAINT ‘||constraint_name||‘ ‘ as v_sql from user_constraints where CONSTRAINT_TYPE=‘R‘) loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop; 
for c in (select ‘ALTER TABLE ‘||TNAME||‘ ENABLE ALL TRIGGERS ‘ AS v_sql from tab where tabtype=‘TABLE‘) loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/ 
commit;
--禁用脚本
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
for c in (select ‘ALTER TABLE ‘||TABLE_NAME||‘ DISABLE CONSTRAINT ‘||constraint_name||‘ ‘ as v_sql from user_constraints where CONSTRAINT_TYPE=‘R‘) loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop; 
for c in (select ‘ALTER TABLE ‘||TNAME||‘ DISABLE ALL TRIGGERS ‘ AS v_sql from tab where tabtype=‘TABLE‘) loop
dbms_output.put_line(c.v_sql);
begin
execute immediate c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
end;
/
commit;

oracle查看用户信息

标签:convert   int   lin   ted   roles   需要   grant   nbsp   from   

人气教程排行