Oracle中tablesinfo_oracle table info

--在删除一个表中的全部数据时,须使用

TRUNCATE TABLE

--因为用DROP TABLE,DELETE * FROM 表名时,TABLESPACE表空间该表的占用空间并未释放,反复几次DROP,DELETE操作后,该TABLESPACE上百兆的空间就被耗光了。

--删除指定用户所有表的方法

select 'Drop table '||table_name||';' from all_tables

where owner='要删除的用户名(注意要大写)';

--获取当前用户下所有的表:

select table_name from user_tables;

--删除某用户下所有的表数据:

select 'truncate table ' || table_name from user_tables;

--删除用户下所有表的语句:

select 'drop table'||table_name||'cascade constraints;' from user_tables;

--获取表:

select table_name from user_tables; //当前用户的表

select table_name from all_tables; //所有用户的表

select table_name from dba_tables; //包括系统表

select table_name from dba_tables where owner='用户名'

--获取表字段:

select * from user_tab_columns where Table_Name='用户表';

select * from all_tab_columns where Table_Name='用户表';

select * from dba_tab_columns where Table_Name='用户表';

--获取表注释:

select * from user_tab_comments;

select * from dba_tab_comments;

select * from all_tab_comments;

--获取字段注释:

select * from user_col_comments;

select * from dba_col_comments;

select * from all_col_comments;

--禁止外键

/*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'

--禁用/启用外键和触发器

--启用脚本

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值