Droping all tables in a schema
how to drop all tables in a schema with out logging in that schema and having logged in as sys user?
Thanks in advance
Edited by: Prasanna.N on May 17, 2010 11:48 PM
Prasanna.N wrote:
Hi,
i get this error
ERROR at line 5:
ORA-06550: line 5, column 9:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe
when giving
begin
for t in (select table_name from dba_tables where owner = 'SCOTT')
loop
execute immediate 'drop table SCOTT.' || t.table_name || 'purge';
end loop;
/I just wrote for loop, of course you have to write inside begin..end block:
begin
for t in (select table_name from dba_tables where owner = 'SCOTT')
loop
execute immediate 'drop table SCOTT.' || t.table_name || ' purge';
end loop;
end;
/
Similar Messages
-
Can we export DATA from all tables in a schema?
Hi,
I have a question; Can we export all the DATA from all the tables present in the schema to any source (eigther CSV, TXT, DAt, etc..)?
Or
Can I have a PL/SQL procedure to display DATA from all Tables in a schema?
With Best Regards,
- NaveedHi,
This is pretty much what you need.
DECLARE
V_COUNT NUMBER;
v_sql varchar2(1000);
IN_OWNER_NAME VARCHAR2(100) := 'AP' ; -- SCHEMA NAME
TYPE T_COL_NAME is table of varchar2(1000) index by binary_integer;
v_col_tbl t_col_name;
BEGIN
FOR i in
(SELECT object_name
FROM dba_objects
WHERE owner = IN_OWNER_NAME
AND object_type ='TABLE'
and rownum < 2)
LOOP
v_sql := 'SELECT COUNT(*) FROM ' || i.object_name ;
EXECUTE IMMEDIATE v_sql INTO V_COUNT;
if v_count > 0 then
v_sql := 'SELECT * FROM ' || i.object_name ;
select column_name
bulk collect
into v_col_tbl
from DBA_TAB_COLUMNS
WHERE TABLE_NAME = I.OBJECT_NAME
AND OWNER = IN_OWNER_NAME;
-- start selecting the column and exporting using the column names selected.
end if;
if v_col_tbl.count > 0 then
for i in v_col_tbl.first .. v_col_tbl.last
loop
DBMS_OUTPUT.PUT_lINE(v_col_tbl(i));
end loop;
end if;
DBMS_OUTPUT.PUT_lINE( i.object_name || '-' || v_count);
END LOOP;
END;
- Ronel -
How to delete all rows in all tables of a schema in Oracle?
Hi all,
I want to delete all records of all tables of a schema and I think there should be some statement for this but I don't know how?
may you help?
Edited by: user8105261 on Nov 25, 2009 11:06 PMuser8105261 wrote:
Hi all,
I want to delete all records of all tables of a schema and I think there should be some statement for this but I don't know how?
may you help?
Edited by: user8105261 on Nov 25, 2009 11:06 PMA typical way to reset a schema (e.g. to recreate a schema on the test database) is totally different.
1) Drop the user
2) recreate the user including table scripts from
2a) your version control system
2b) from a export dumpfile using the "nodata" option while importing -
Need to grant DML privileges to all tables in few schemas
Hi,
I need to grant DML privileges to all tables in few schemas to a role. How can I achieve that?
I thought it's below syntax but it doesn't work. Please advice.
grant ALL ON ALL TABLES IN SCHEMA <Schema_name> TO <role_name>;Thanks,
GangadharGR wrote:
Hi,
I need to grant DML privileges to all tables in few schemas to a role. How can I achieve that?
I thought it's below syntax but it doesn't work. Please advice.
grant ALL ON ALL TABLES IN SCHEMA <Schema_name> TO <role_name>;
There is no single command to grant privileges at that level. There are either ANY privileges or privileges on an object.
You can write a bit of code to generate and execute what you want, but you would have to rerun it if any new tables were created. -
Grant select on all table of a schema to role
Hi , is it possible to grant select on all table on a schema to a role?
To grant SELECT on all tables of the current schema to particular role or user:
SELECT 'GRANT SELECT ON '||TABLE_NAME||' TO READ_ONLY_ROLE;' COMMAND
FROM (
SELECT TABLE_NAME
FROM ALL_TABLES
WHERE OWNER = (SELECT USER FROM DUAL)
Then copy and execute the result commands, eg:
GRANT SELECT ON DEPT TO READ_ONLY_ROLE;
GRANT SELECT ON EMP TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_USERS TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_CUSTOMERS TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_ORDERS TO READ_ONLY_ROLE; -
All columns of all table in one schema
Hi
All,
Oralce 10.2.0.3
I want to count all columns in all the table in one particular schema.
How can I do that?
which view i should use to count all cloumns of all tables in particular schema?
Thanksvishal patel wrote:
we needed for our data conversion project..I don't know how you'll use the number of columns in all a schema for data conversion. Some columns are duplicated (e.g. PK/FK), should they really count for two ?
A data conversion means you should actually know what are the columns used for, not how many they are.
one more question that count include hidden columns
what is hidden column used for ? I can not see those columns in actual table.See here an example :
Re: Difference btwn user_tab_cols & user_tab_columns
Nicolas. -
Program (PL/SQL) for count the registers of all tables in a schema
Hi...
I create a little program , for count the registers of all tables in the schema...
If you need , send me your email...
Atte
HectorHi,
You can create a script by yourself by executing the script mentioned below:
Connect as sys or system....
SQL> spool test.sql
SQL> select 'select count(*) from '||owner||'.'||table_name||';' from dba_tables;
SQL> spool off;
Hope this helps.
Regards,
-Praveen.
http://myracle.wordpress.com -
What privilege is needed to browse all tables in a schema
I used SQLPlus to login to DB. When I clicked "table" in the left side window, no tables is shown. What privilege is needed to browse all tables in a schema?
Thanks.SQL*Plus is a command-line interface. There is no side window to click on. Perhaps you're talking about SQL Programmer? Or are you talking about some other tool?
What user are you logging in as? What user owns the objects? Do you just want to see that the tables exist? Or do you want to be able to see the data as well?
Justin -
How to drop all tables in perticular schema??
Hi,
I am new in oracle.
I want to drop all tables in one perticular schema,
Please tell me solution.
PratHameshIf your few of your tables have referential intigrity constraints and trying to drop master table whithout droping child table first, oracle will produce an error.
Better option would be to drop the entire schema and then create a new schema with the same name.
on sql plus.
set long size 20000
select dbms_metadata.get_ddl('USER','USERNAME') from dual;
--then save the above output to create the user later.
drop username cascade
use the above saved script to create the user again.
Jaffar -
How can count no of rows in all tables in one schema
hi all
i want to cound no of rows in my schema ( all tables)
eg. i have 36 tables
i want to know no of rows in every tables in only one query through sql or plsql
how can i do..
regards
mohammadi
Message was edited by:
Mohdidubai52hi
thanx for ur reply
but i got error....
SQL> ED
Wrote file afiedt.buf
1 DECLARE
2 v_rowNo NUMBER := 0;
3 v_sum NUMBER := 0;
4 v_tableName VARCHAR2(100);
5 CURSOR c1 IS
6 SELECT table_name
7 FROM user_tables;
8 BEGIN
9 FOR counter IN c1 LOOP
10 DBMS_OUTPUT.PUT_LINE(counter.table_name);
11 EXECUTE IMMEDIATE 'SELECT COUNT(1) FROM ' || counter.table_name INTO v_ro
wNo;
12 v_sum := v_sum + v_rowNo;
13 END LOOP;
14 DBMS_OUTPUT.PUT_LINE('Number of rows: ' || v_sum);
15* END;
16 /
DECLARE
ERROR at line 1:
ORA-00933: SQL command not properly ended
ORA-06512: at line 11
again
thanx
regards
Mohammadi -
Searching for a values in all tables in a schema
Hi All,
Is there any way/logic to find a value in unknown
fileds of unknown tables in a schema.
Just out of curiosity, I am posting this question.
Thanks in advance.
Regards,
SriniI already answered to a similar post last week.
Have a look at this site :
how do I find in a ViewTable what table has a specific column?
-- Shailender Mehta -- -
Deleting the contents of all tables in a schemas
hi ,
can someone tell me if there is a way of deleting the contents of all tables , without dropping any.because the schema is big and just want to empty all tables at the same time.
thanks in advance.Hi,
>>Will they be enabled after running the script?
Well, of course they need to be re-enabled ... don't you think?
SQL> create table a (id number primary key);
Table created.
SQL> create table b (id number constraint fk_b_a references a);
Table created.
SQL> select constraint_name,status from user_constraints where table_name='B';
CONSTRAINT_NAME STATUS
FK_B_A ENABLED
SQL> truncate table a;
truncate table a
ERROR at line 1:
ORA-02266: unique/primary keys in table referenced by enabled foreign keys
SQL> alter table b disable constraint fk_b_a;
Table altered.
SQL> truncate table a;
Table truncated.
SQL> select constraint_name,status from user_constraints where table_name='B';
CONSTRAINT_NAME STATUS
FK_B_A DISABLED
SQL> alter table b enable constraint fk_b_a;
Table altered.
SQL> select constraint_name,status from user_constraints where table_name='B';
CONSTRAINT_NAME STATUS
FK_B_A ENABLEDCheers
Legatti -
Grant to all tables on my schema
I am fairly new to Oracle and I need to grant "select, update, insert on all mytalbes to roleone, then grant that role to all my users.
well, I have about 50 tables and 20 users.
So far the most automated way I have come up with is:
grant select, update, insert on table1 to role1;
then I after that, I do:
grant role1 to userone;
I am sure there is a way to do this in some sort of procedure. I dont have DBA privs. I own all of the tables on my schema and those are the ones that I need to grant the privs to users.
would you guys show me how to do this?
thanks a bunch!You have to grant the privileges on each table to the role and then grant the role to each user, so you need 70 GRANT statements. You can write some dynamic SQL to generate the grants, though
DECLARE
sqlStmt VARCHAR2(4000);
BEGIN
FOR x IN (SELECT * FROM user_tables)
LOOP
sqlStmt := 'GRANT SELECT, UPDATE, INSERT ON ' || x.table_name || ' TO role1';
EXECUTE IMMEDIATE sqlStmt;
END LOOP;
END;
DECLARE
sqlStmt VARCHAR2(4000);
BEGIN
FOR x IN (SELECT * FROM dba_users)
LOOP
sqlStmt := 'GRANT role1 TO ' || x.username;
EXECUTE IMMEDIATE sqlStmt;
END LOOP;
END;Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Deleting all tables in a schema
I am trying to delete all tables in a given schema. Any ideas how to do this via t-sql appreciated.
tia,
edm2If the tables are not dependent one of the other, then simple query like this:
DECLARE @sql NVARCHAR(max)
SELECT @sql = stuff((
SELECT ', ' + quotename(table_schema) + '.' + quotename(table_name)
FROM INFORMATION_SCHEMA.Tables
WHERE table_schema = 'dbo'AND TABLE_TYPE = 'BASE TABLE'
ORDER BY table_name
FOR XML path('')
), 1, 2, '')
SET @sql = 'DROP TABLE ' + @sql
PRINT @sql
BEGIN TRANSACTION
EXECUTE (@SQL)
ROLLBACK TRANSACTION
If they are related, then the script will be much more complex as you need to drop tables in the right order.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles -
Analyze all tables of one schema
hi,
the analyze table command is:
analyze table hr.employees compute statistics;
Now I want analyze all tables in the hr schema
how can I do it in a easy way,
thanks,
Zhiwei.the only way to disable monitoring (globally) is to set statistics_level=basic.Exactly.
SYS@db102 SQL> select table_name,monitoring from dba_tables
2 where table_name like 'TEST%';
TABLE_NAME MON
TEST_P YES
TEST_MV YES
TEST_F YES
TEST11 YES
TEST YES
TEST_TABLE YES
TEST_PART YES
TEST_LOB YES
TEST_EMP YES
TESTDECIMAL YES
TEST3 YES
TEST1_DL2 YES
TEST01 YES
13 rows selected.
SYS@db102 SQL> alter system set statistics_level=basic;
System altered.
SYS@db102 SQL> select table_name,monitoring from dba_tables
2 where table_name like 'TEST%';
TABLE_NAME MON
TEST_P NO
TEST_MV NO
TEST_F NO
TEST11 NO
TEST NO
TEST_TABLE NO
TEST_PART NO
TEST_LOB NO
TEST_EMP NO
TESTDECIMAL NO
TEST3 NO
TEST1_DL2 NO
TEST01 NO
13 rows selected.
SYS@db102 SQL> that's what I meant by "in 10g you have to do it explicitly".
Maybe you are looking for
-
How to run a script on Oracle server from isqlplus
Hi I am trying to run a script on my workstation from Oracle server through isqlplus workarea. I entered following command and get the following error. i have enabled isqlplus URL by editing web.xml file already. Can please someone help how to run th
-
Help with Applescript and Admin Privelages
I just started using Applestript a few months ago and I can't figure out how to give my script Admin rights. Basically, it turns on and off my internet sharing and file sharing through dialog boxes. I copied and pasted the whole code below if you wan
-
Sequence doesn't play the sound.. help?
Hey.. I've just got FCE4 and I've encountered some problems. I've managed to overcome the "Not Rendered" issue, but now while I play the imported video already on the timeline, on the canvas, no sound is played. Not from the .dv files, and not from t
-
Is there a way to save Preferences
I go into Preferences in Logic Pro 9 and click Midi>Sync Tab and change some things around so that my Akai MPK49 Midi Controller can function properly with Logic. Every time I start Logic or Open a New File, I have to go in and set those Preferences
-
When I reboot my windows desktop i get a message that says apsdaemon.exe can not start because msvcr80.dll is missing. How do i fix this? Thank you in advance.