To drop all the tables in a database
hi,
I have 25000 tables in a database.I want ot delete all the tables and then i have to import the dump.For deleting all the tables what query has to be given.
Thanks in advance,
R.Ratheesh
The code would be
BEGIN
FOR c IN (SELECT owner,
table_name
FROM all_tables
WHERE owner IN ('YOUR_OWNER1', 'YOUR_OWNER2_ETC'))
LOOP
EXECUTE IMMEDIATE 'drop table '
|| c.owner
|| '.'
|| c.table_name
|| ' cascade constraints';
END LOOP;
END;
the user ,tablespaces ,datafiles has to be recreatedbut still dropping the user would be the simplest option
you don't have to recreate tablespaces and datafiles for that.
Similar Messages
-
How to delete/drop all the tables from SQL Server Database without using Enterprise Manager?
I tried using DROP Tables, Truncate Database, Delete and many more but it is not working. I want to delete all tables using Query Analyzer, i.e. through SQL Query.
Please help me out in this concern.
Nishith ShahInformative thread indeed. Wish I saw it early enough. Managed to come up with the code below before I saw this thread.
declare @TTName Table
(TableSchemaTableName
varchar
(500),
[status] int
default 0);
with AvailableTables
(TableSchemaTableName)
as
(select
QUOTENAME(TABLE_SCHEMA)
+
+
QUOTENAME(TABLE_NAME)
from
INFORMATION_SCHEMA.TABLES)
insert into @TTName
(TableSchemaTableName)
select *
from AvailableTables
declare @TableSchemaTableName varchar
(500)
declare @sqlstatement nvarchar
(1000)
while 1=1
begin
set @sqlstatement
=
'DROP TABLE '
+ @TableSchemaTableName
exec
sp_executeSQL
@sqlstatement
print
'Dropped Table : '
+ @TableSchemaTableName
update @TTName
set [status]
= 1
where TableSchemaTableName
= @TableSchemaTableName
if
(select
count([Status])
from @TTName
where [Status]
= 0)
= 0
break
end -
How to truncate all the tables of my database
hi guys
I am using SQL Server 2012 , i need to delete all the data present in my database .I mean i want to truncate all the tables in my database , so please suggest me the easiest way .If the tables are referenced by FK it will be failed....
Basically you can use the below statetemnt
DECLARE @TruncateStatement nvarchar(4000)
DECLARE TruncateStatements CURSOR LOCAL FAST_FORWARD
FOR
SELECT
N'TRUNCATE TABLE ' +
QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)
FROM
INFORMATION_SCHEMA.TABLES
WHERE
TABLE_TYPE = 'BASE TABLE' AND
OBJECTPROPERTY(OBJECT_ID(QUOTENAME(TABLE_SCHEMA) +
N'.' +
QUOTENAME(TABLE_NAME)), 'IsMSShipped') = 0
OPEN TruncateStatements
WHILE 1 = 1
BEGIN
FETCH NEXT FROM TruncateStatements INTO @TruncateStatement
IF @@FETCH_STATUS <> 0 BREAK
RAISERROR (@TruncateStatement, 0, 1) WITH NOWAIT
EXEC(@TruncateStatement)
END
CLOSE TruncateStatements
DEALLOCATE TruncateStatements
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Script for dropping all the tables
Hello:
Can somebody share with me a script that will delete all the tables in a schema?
Thanks.I think what Justin was getting at is this: we cannot drop tables that are referenced by foreign keys. So before we can drop all tables weed to drop all referencing constraints. Which makes this script even more dangerous - you may wish to abort if other schemas reference the "droppee".
Let's be careful out there!
Cheers, APC
declare
cursor fks is
select owner,table_name, constraint_name
from all_constraints
where r_owner='&&schema_to_delete'
and constraint_type = 'R';
cursor tables is
select owner,table_name
from all_tables
where owner='&&schema_to_delete';
begin
for b in fks
loop
dbms_output.put_line( 'drop fk constraint '||b.owner||'.'||b.table_name||'.'||b.constraint_name);
execute immediate 'alter table '||b.owner||'.'||b.table_name||' drop constraint '||b.constraint_name;
end loop;
for c in tables
loop
dbms_output.put_line( 'drop table '||c.owner||'.'||c.table_name);
execute immediate 'drop table '||c.owner||'.'||c.table_name;
end loop;
end;
/ -
Search in database in all the tables
Hi friends,
I want to search following text in database in all the tables :
Paris-Murex BO for BNL- Panorama(Roma) / BNL-Panorama for Paris-Murex BO(Roma)
above text is thr in our client site which is getting retrieved from database, I know the database instance name but but dont know from which table this value (text) is comming from.
please help it's urgent!!!This is a depressingly common request. Why are there so many shonky undocumented applications out there?
Anyway, the solution for a one-off exercise is this brute force approach. It's not pretty and the performance will be Teh Suck, but it will find the string. If you think that the string might be in more than one column you should remove the EXIT and let the thing grind on for as long as it takes.
set serveroutput on
declare
n number;
begin
for r in ( select owner, table_name, column_name
from all_tab_columns
where owner not in ('SYS', 'SYSTEM')
and data_type in ('CHAR', 'VARCHAR2')
and data_length >= 43 )
loop
dbms_output.put_line('checking!!'||r.owner||'.'||r.table_name||'.'||r.column_name);
begin
execute immediate 'select 1 from '||r.owner||'.'||r.table_name
||' where '||r.column_name||' like ''%Paris-Murex BO for BNL- Panorama(Roma) / BNL-Panorama for Paris-Murex BO(Roma)%'''
||' and rownum = 1'
into n;
dbms_output.put_line('found it!!'||r.owner||'.'||r.table_name||'.'||r.column_name);
exit;
exception
when no_data_found
then
null;
end;
end loop;
end;
/If you have CLOBs and BLOBs you want to check as well then you'll need to run through a second query using CONTAINS(). Implementing that is left as an exercise for the reader.
Note that if you want to do this on a regular basis then you need a completely different, more architectural approach.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Hi All
I have nearly 70 procedures in my database.
I want to get all the distinct table names used in the 70 procedures.
Is it possible?
Note:
All the table names are prefixed by schema name like DEVSRC.table_name.
Please advice
Thanks
JoJohney wrote:
Hi VT
One doubt.
This query will give the table names of only select stmt used in the procedure
or
List of table names that are with in any DML operations inside the procedure?
Thanks
JoIt will give all the table either used in select or in any DML..
You can also check by creating a temp proc
SQL> drop procedure proc_test;
Procedure dropped.
SQL> select name, referenced_name, dependency_type from user_dependencies
2 where type = 'PROCEDURE' and referenced_type = 'TABLE' and name='PROC_TEST';
no rows selected
SQL> create or replace
2 PROCEDURE proc_test
3 IS
4 v_ID number;
5 v_PRID number;
6 v_PRLID number;
7 v_DATERECEIVED date;
8 Cursor C1 is
9 select * from table_c;
10 BEGIN
11 open c1;
12 LOOP
13 FETCH c1 INTO v_ID,v_PRID,v_PRLID,v_DATERECEIVED;
14 EXIT WHEN c1%NOTFOUND;
15 insert into table_b values(v_ID,v_PRID,v_PRLID,v_DATERECEIVED);
16 Commit;
17 END LOOP;
18 CLOSE C1;
19 END;
20 /
Procedure created.
SQL> select name, referenced_name, dependency_type from user_dependencies
2 where type = 'PROCEDURE' and referenced_type = 'TABLE' and name='PROC_TEST';
NAME
REFERENCED_NAME DEPE
PROC_TEST
TABLE_B HARD
PROC_TEST
TABLE_C HARD
SQL> Regards
Umesh -
How to find all the tables associated for a particular transaction
Hi-
May I know how to find all the tables, related(foreign key) tables for a transaction within SAP GUI?
Up to my technical knowledge, this can be achieved by looking database diagrams from DB level. But that would be for entire database as a whole. What I'm expecting is to see transaction level relative tables that too from SAP GUI. Please share the possibilities if any.
Regards
SekharDear Micky Oestreich
May be we possess expertise or high level experience, it should not show up in our way of communication. Every professional starts with the basic stuff to learn. When the question is raised in such minimum polite way, the same level of courtesy is expected in return. If you felt my question was basic, you might have refused it gently. If you are in good mood or bad mood it doesn't matters.
Hi Vengal Rao
Thanks for your response. It helped me.
Regards
Sekhar -
To find particular value in all the tables in the db
Hi All
I need to find out all the tables, corresponding column name by querying a particular string that appears in any of the columns in the any of the tables in the db.
Please help me of this.
ThanksOh dear you want to look for a particular data in all the tables in the database and say this data is available in these tables in these columns. Oh boy thats going to cost you a lot. why do you want to do that. can you share with us why you want to do that.
Thanks,
Karthick. -
Selecting string from all the tables in databse
Hi All,
I need a help in finding the data from all the database tables at one time using single query.
For e.g. I wanna search a string 'ABC' in all the database tables for a schema.
I want to find out,which all tables (in either of its columns) contain this string strored inside themselves.
For brand name changing,I need to find out all the tables and in turn all the columns containing that string where databse consisting of 1000 tables.
Could anyone suggest me some option for this?Is it possible to avoid this tedious task to search individual table?Why is it necessary to search every column? Does your data model permit the brand name to be stored in any column?
Whatever.
I suggest starting with dba_tab_columns (where owner = 'WHATEVER') and look for those tables/columns that could possibly hold the brand name. You can eliminate NUMBER and DATE columns and VARCHAR columns that are too short.
Spool that out to another script where each select statement is like this:
SELECT 'TABLE_NAME.COLUMN_NAME', column_name
FROM table_name
WHERE UPPER(COLUMN_NAME) LIKE '%BRAND NAME%'
AND rownum = 1; -
Select data from all the table names in the view
Hi,
"I have some tables with names T_SRI_MMYYYY in my database.
I created a view ,Say "Summary_View" for all the table names
with "T_SRI_%".
Now i want to select data from all the tables in the view
Summary_View.
How can i do that ? Please throw some light on the same?
Thanks and Regards
Srinivas CheboluSrinivas,
There are a couple of things that I am unsure of here.
Firstly, does your view definition say something like ...
Select ...
From "T_SRI_%"
If so, it is not valid. Oracle won't allow this.
The second thing is that your naming convention for the
tables suggests to me that each table is the same except
that they store data for different time periods. This would be
a very bad design methodology. You should have a single
table with an extra column to state what period is referred to,
although you can partition it into segments for each period if
appropriate.
Apologies if i am misinterpreting your question, but perhaps
you could post your view definition and table definitions
here. -
Dropping all deployed tables in OWB 10.2.0.3.0
I am running OWB 10.2.0.3.0 and have multiple schemas containing deployed tables. This is a test instance and I would like to drop all the old tables and recapture some of the space. Is WB_RT_VERSION_FLAG the only table I need to keep intact to keep OWB functioning? Should I also leave CREATE$JAVA$LOB$TABLE and TRACE if it exists? Thanks.
Hi,
you must keep WB_RT_VERSION_FLAG, all the synonyms (created by owb) and the roles of a target user. All other objects may be dropped.
You should consider dropping the objects using control center manager (use context menu on the module an set the action to drop for all objects at once) in order to have the deployment status correctly.
Regards,
Carsten. -
Script to generate all the tables and objects in a schema
how to write a script to generate all the tables and objects in a schema.
with toad the no of tables generated is not matching when i check from schema .Dear Sidhant,
Try this script:
set termout off
set feedback off
set serveroutput on size 100000
spool ddl_schema.sql
begin
dbms_output.put_line('--');
dbms_output.put_line('-- DROP TABLES --');
dbms_output.put_line('--');
for rt in (select tname from tab order by tname) loop
dbms_output.put_line('DROP TABLE '||rt.tname||' CASCADE CONSTRAINTS;');
end loop;
end;
declare
v_tname varchar2(30);
v_cname char(32);
v_type char(20);
v_null varchar2(10);
v_maxcol number;
v_virg varchar2(1);
begin
dbms_output.put_line('--');
dbms_output.put_line('-- CREATE TABLES --');
dbms_output.put_line('--');
for rt in (select table_name from user_tables order by 1) loop
v_tname:=rt.table_name;
v_virg:=',';
dbms_output.put_line('CREATE TABLE '||v_tname||' (');
for rc in (select table_name,column_name,data_type,data_length,
data_precision,data_scale,nullable,column_id
from user_tab_columns tc
where tc.table_name=rt.table_name
order by table_name,column_id) loop
v_cname:=rc.column_name;
if rc.data_type='VARCHAR2' then
v_type:='VARCHAR2('||rc.data_length||')';
elsif rc.data_type='NUMBER' and rc.data_precision is null and
rc.data_scale=0 then
v_type:='INTEGER';
elsif rc.data_type='NUMBER' and rc.data_precision is null and
rc.data_scale is null then
v_type:='NUMBER';
elsif rc.data_type='NUMBER' and rc.data_scale='0' then
v_type:='NUMBER('||rc.data_precision||')';
elsif rc.data_type='NUMBER' and rc.data_scale<>'0' then
v_type:='NUMBER('||rc.data_precision||','||rc.data_scale||')';
elsif rc.data_type='CHAR' then
v_type:='CHAR('||rc.data_length||')';
else v_type:=rc.data_type;
end if;
if rc.nullable='Y' then
v_null:='NULL';
else
v_null:='NOT NULL';
end if;
select max(column_id)
into v_maxcol
from user_tab_columns c
where c.table_name=rt.table_name;
if rc.column_id=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (v_cname||v_type||v_null||v_virg);
end loop;
dbms_output.put_line(');');
end loop;
end;
declare
v_virg varchar2(1);
v_maxcol number;
begin
dbms_output.put_line('--');
dbms_output.put_line('-- PRIMARY KEYS --');
dbms_output.put_line('--');
for rcn in (select table_name,constraint_name
from user_constraints
where constraint_type='P'
order by table_name) loop
dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD (');
dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
dbms_output.put_line ('PRIMARY KEY (');
v_virg:=',';
for rcl in (select column_name,position
from user_cons_columns cl
where cl.constraint_name=rcn.constraint_name
order by position) loop
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.constraint_name;
if rcl.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
dbms_output.put_line(')');
dbms_output.put_line('USING INDEX );');
end loop;
end;
declare
v_virg varchar2(1);
v_maxcol number;
v_tname varchar2(30);
begin
dbms_output.put_line('--');
dbms_output.put_line('-- FOREIGN KEYS --');
dbms_output.put_line('--');
for rcn in (select table_name,constraint_name,r_constraint_name
from user_constraints
where constraint_type='R'
order by table_name) loop
dbms_output.put_line ('ALTER TABLE '||rcn.table_name||' ADD (');
dbms_output.put_line ('CONSTRAINT '||rcn.constraint_name);
dbms_output.put_line ('FOREIGN KEY (');
v_virg:=',';
for rcl in (select column_name,position
from user_cons_columns cl
where cl.constraint_name=rcn.constraint_name
order by position) loop
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.constraint_name;
if rcl.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
select table_name
into v_tname
from user_constraints c
where c.constraint_name=rcn.r_constraint_name;
dbms_output.put_line(') REFERENCES '||v_tname||' (');
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.r_constraint_name;
v_virg:=',';
select max(position)
into v_maxcol
from user_cons_columns c
where c.constraint_name=rcn.r_constraint_name;
for rcr in (select column_name,position
from user_cons_columns cl
where rcn.r_constraint_name=cl.constraint_name
order by position) loop
if rcr.position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcr.column_name||v_virg);
end loop;
dbms_output.put_line(') );');
end loop;
end;
begin
dbms_output.put_line('--');
dbms_output.put_line('-- DROP SEQUENCES --');
dbms_output.put_line('--');
for rs in (select sequence_name
from user_sequences
where sequence_name like 'SQ%'
order by sequence_name) loop
dbms_output.put_line('DROP SEQUENCE '||rs.sequence_name||';');
end loop;
dbms_output.put_line('--');
dbms_output.put_line('-- CREATE SEQUENCES --');
dbms_output.put_line('--');
for rs in (select sequence_name
from user_sequences
where sequence_name like 'SQ%'
order by sequence_name) loop
dbms_output.put_line('CREATE SEQUENCE '||rs.sequence_name||' NOCYCLE;');
end loop;
end;
declare
v_virg varchar2(1);
v_maxcol number;
begin
dbms_output.put_line('--');
dbms_output.put_line('-- INDEXES --');
dbms_output.put_line('--');
for rid in (select index_name, table_name
from user_indexes
where index_name not in (select constraint_name from user_constraints)
and index_type<>'LOB'
order by index_name) loop
v_virg:=',';
dbms_output.put_line('CREATE INDEX '||rid.index_name||' ON '||rid.table_name||' (');
for rcl in (select column_name,column_position
from user_ind_columns cl
where cl.index_name=rid.index_name
order by column_position) loop
select max(column_position)
into v_maxcol
from user_ind_columns c
where c.index_name=rid.index_name;
if rcl.column_position=v_maxcol then
v_virg:='';
end if;
dbms_output.put_line (rcl.column_name||v_virg);
end loop;
dbms_output.put_line(');');
end loop;
end;
spool off
set feedback on
set termout on Best Regards,
Francisco Munoz Alvarez
www.oraclenz.com -
Problem while displaying all the table names from a MS Access Data Source.
I started preparing a small Database application. I want to display all the Table Names which are in the 'MS Access' Data Source.
I started to executing by "Select * from Tab" as if in SQL.
But i got an error saying that "Not able to resolve Symbol 'Tab' in the query".
Please let me know how can i display all the table Names in the MS Access Dats Source.Here i am developing the application in Swing using JDBC for accessing the database.
I want to display all the Table names from the data source in a ListBox for easy selection of tables to view their details. -
How to move all the tables from one tablespace to other for a whole schema
Hi,
Is there any way to move all the tables in a schema from one tablespace to other?
If so please help me out to do that.
Thanks
Regards
Gathahi,
here is the steps to move SCOTT's objects from their current tablespace to a NEW_TABLESPACE
would be:
1) do an export of all of scott's objects. Make sure no one modifies them after you
begin this process. You will lose these changes if they do.
$ exp userid=scott/tiger owner=scott
2) you would drop all of scotts tables. This will get the indexes as well. I don't
suggest dropping the user SCOTT but rather dropping scott's objects. Dropping scott
would cause any system priveleges SCOTT has to disappear and the import would not restore
them. This script can be used to drop someones tables:
set heading off
set feedback off
set verify off
set echo off
spool tmp.sql
select 'drop table &1..' || table_name || ' cascade constraints;'
from dba_tables
where owner = upper('&1')
spool off
@tmp.sql
3) You would modify the user to not have unlimited tablespace (else the IMP will just
put the objects right back into the tablespace they came from) and then give them
unlimited quota's on the new tablespace you want the objects to go into and on their
temporary tablespace (for the sorts the index creates will do)
alter user SCOTT default tablespace NEW_TABLESPACE
revoke unlimited tablespace from SCOTT
alter user SCOTT quota unlimited on NEW_TABLESPACE
alter user SCOTT quota unlimited on SCOTTS_TEMPORARY_TABLESPACE
4) you will IMP the data back in for that user. IMP will rewrite the create statements
to use the users default tablespace when it discovers that it cannot create the objects
in their original tablespace. Please make sure to review the file imp.log after you do
this for any and all errors after you import.
imp userid=scott/tiger full=y ignore=y log=imp.log
5) you can optionally restore 'unlimited tablespace' to this user (or not). If you do
not, this user can only create objects in this new tablespace and temp (which in itself
is not a bad thing)...
Regards,
Mohd Mehraj Hussain
http://mehrajdba.wordpress.com -
All CX* Tables in Local Database are empty
Hello!
We have a one mobile client and at this time i see a problem that all custom tables in local database empty
In client folder outbox only one file "Marker". All server component work fine. SRF one for server and client.
I don't know for what reason it happened. Need help.
Thank you.Hi,
you need configure the custom tables in dock object or you need include the base table in base table property in table object.
If your custom table related a base table, for example, a 1:M table, where a S_ table is a parent table and CX_ is a child table, and base table property in table object (tools) populated with S_ table, in this process, you don't need config the dock object.
After this steps, you need config Siebel anywhere to synchronize local database with new change (CX_ table is updated / created in local database).
If you don't want this method, you can generate and extract a new database. The CX_ tables are generated in local database, but when apply a new CX_ tables, colunm, or any config in tables, you need generate and extract a new local database again.
Regards.
Maybe you are looking for
-
Audigy 4 platinum pro Microphone im
Simple one here, i'm just about to buy some leads to connect my condensor mic to my external hub. I just bought a preamp, yet don't have all the leads for it to work. Will a 'balanced /4" TRS connector' fit into the 'Mic imput'/'line-in' of my Audigy
-
Lightroom 5.5 edit in Photoshop CC 2014 not working.
Has anyone had problems using the edit in photoshop cc 2014 option from the Lightroom 5 drop-down menu? It won't open in photoshop for some reason... never hat problems with photoshop cc.
-
Help with a Photosmart Pro B9180
Our problem is no matter what we set the paper size for in our computer when we send a picture is says "paper size too small" or "paper size too large". We have cleaned around the tray. Reset the printer and no matter what we do from your online help
-
Check frame in conditional statement
What's the proper "if" syntax for checking the current frame of another movie clip? I have no idea how to say it. I want to check if instance name "port_mc" (from the main timeline) is at frame 30 for my condition. My code with the unfinished if: ant
-
How do I parse this string?
I have a string of html , which looks like this: <head></head><body><p>Stringof<strong><em>tags</em></strong>inhtml</p> I have to go ahead a search for the tags and put them into a tree. for instance. <head> would be the root, then I would go to <p>