Home » RDBMS Server » Server Administration » Describing all the tables in a database
Describing all the tables in a database [message #374495] Thu, 14 June 2001 17:42 Go to next message
Asim
Messages: 8
Registered: October 2000
Junior Member
Hi
I am trying to describe all the tables in a database.

We use desc or describe tablename; to describe a table, but what is the command to describe all the tables in a database (i don't need the system tables)

Once i log into sqlplus as a say ABC (SID or HostString) as a user then if i do a desc table name i get column name, data type and null not null etc but i i need that for all the tables in that ABC database

Thanks
-Asim
Re: Describing all the tables in a database [message #374524 is a reply to message #374495] Fri, 15 June 2001 18:34 Go to previous messageGo to next message
Andrew again...
Messages: 270
Registered: July 2000
Senior Member
try this in sqlplus...

/*
|| tab_descr.sql
|| Run this script in the current user to generate a report describing the
|| the tables. 7.x and above compatible.
|| AHM, 01/30/2001, Original version
*/
set pagesize 0
set feedback off
set verify off
column a new_val todaysdate
select to_char(sysdate,'DD-MON-YYYY HH24:MI') a from dual;
column b new_val thisuser
column c new_val thisdb
select to_char(sysdate,'DD-MON-YYYY HH24:MI') a,
user b,
substr(global_name, 1, 20) c
from global_name;
column Table_Descr format a80 wrap

spool tmp_script.sql
PROMPT spool &thisuser._&thisdb..txt
PROMPT prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROMPT prompt TABLE DEFINITION REPORT &todaysdate
PROMPT prompt FOR SCHEMA OWNER &thisuser @ &thisdb
PROMPT prompt NB: Only Tables are described - NOT Synonyms.
PROMPT prompt . Tables excluded: MLOG$%, %_H
PROMPT prompt Created by tab_descr.sql
PROMPT prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROMPT prompt
PROMPT prompt

SELECT 'prompt Table #'||to_char(ROWNUM, '000')||' - '||owner||'.'||table_name||chr(10),
' descr '|| owner||'.'||table_name||';' Table_Descr
FROM (SELECT t1.table_name, t1.owner
FROM all_tables t1
WHERE t1.table_name NOT LIKE 'MLOG$%'
AND t1.table_name NOT LIKE '%_H'
AND t1.owner = upper('&thisuser')
GROUP BY t1.table_name, t1.owner);
PROMPT prompt ~~~ END OF REPORT ~~~
PROMPT spool off
PROMPT prompt your output is in : &thisuser._&thisdb..txt
SPOOL off

@tmp_script.sql
Re: Describing all the tables in a database [message #478135 is a reply to message #374524] Wed, 06 October 2010 09:08 Go to previous messageGo to next message
hem5840
Messages: 3
Registered: October 2010
Junior Member
Hi, I have been looking for something like this today and it's what I want! However, I would like a couple of tweeks Laughing Can anyone help by amending this so it goes into an excel spreadsheet nicely (I tried changing the output to .xls or .csv but it still put one line of info in 1 cell), and also can it list the number of records contained in that table?

Many thanks, Helen x
Re: Describing all the tables in a database [message #478140 is a reply to message #478135] Wed, 06 October 2010 09:33 Go to previous messageGo to next message
ramoradba
Messages: 2456
Registered: January 2009
Location: AndhraPradesh,Hyderabad,I...
Senior Member
Its a Faq.Search before posting.
Read forum guide lines before posting.

Sriram
Re: Describing all the tables in a database [message #478142 is a reply to message #478140] Wed, 06 October 2010 09:44 Go to previous messageGo to next message
hem5840
Messages: 3
Registered: October 2010
Junior Member
Apologies Sriram, I do not understand what you mean. I have searched the forum and this is the closest I can find and gives me mostly what I want, but I would like it tweaked a bit as I said. Can anyone help? Many thanks.
Re: Describing all the tables in a database [message #478144 is a reply to message #478142] Wed, 06 October 2010 09:56 Go to previous messageGo to next message
cookiemonster
Messages: 13923
Registered: September 2008
Location: Rainy Manchester
Senior Member
I don't believe it is tweakable in the way you want.
It just runs a set of describe commands and spools them to a file.
To work in excel you'd need to put seperators between the columns of the describe output and I can't see anyway to do that. It appears desc is always space delimeted - which isn't much use.

To get what you want you'd need to query the data dictiony views - user_tab_cols would be the most usful. If you write an actual query then you can delimit it any way you want.
Re: Describing all the tables in a database [message #478145 is a reply to message #478144] Wed, 06 October 2010 10:02 Go to previous messageGo to next message
Roachcoach
Messages: 1576
Registered: May 2010
Location: UK
Senior Member
When I've mucked about spooling to excel, setting HTML markup seems to work pretty good.

Edit: worked ok with me for a quick "desc dual" command

[Updated on: Wed, 06 October 2010 10:04]

Report message to a moderator

Re: Describing all the tables in a database [message #478158 is a reply to message #478142] Wed, 06 October 2010 12:06 Go to previous messageGo to next message
LKBrwn_DBA
Messages: 487
Registered: July 2003
Location: WPB, FL
Senior Member
hem5840 wrote on Wed, 06 October 2010 10:44
Blah, blah,blah...and gives me mostly what I want, but I would like it tweaked a bit as I said. Can anyone help? Many thanks.


Try this:
/*
|| tab_descr.sql
|| Run this script in the current user to generate a report describing the
|| the tables. 7.x and above compatible.
|| AHM, 01/30/2001, Original version
*/
set pagesize 0
set feedback off
set verify off
column a new_val todaysdate
select to_char(sysdate,'DD-MON-YYYY HH24:MI') a from dual;
column b new_val thisuser
column c new_val thisdb
select to_char(sysdate,'DD-MON-YYYY HH24:MI') a,
user b,
substr(global_name, 1, 20) c
from global_name;
column Table_Descr format a80 wrap

spool tmp_script.sql
--PROMPT spool &thisuser._&thisdb..txt
PROMPT prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROMPT prompt TABLE DEFINITION REPORT &todaysdate
PROMPT prompt FOR SCHEMA OWNER &thisuser @ &thisdb
PROMPT prompt NB: Only Tables are described - NOT Synonyms.
PROMPT prompt . Tables excluded: MLOG$%, %_H
PROMPT prompt Created by tab_descr.sql
PROMPT prompt ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROMPT prompt
PROMPT prompt

SELECT 'prompt Table #'||to_char(ROWNUM, '000')||' - '||owner||'.'||table_name||chr(10),
' descr '|| owner||'.'||table_name||';' Table_Descr
FROM (SELECT t1.table_name, t1.owner
FROM all_tables t1
WHERE t1.table_name NOT LIKE 'MLOG$%'
AND t1.table_name NOT LIKE '%_H'
AND t1.owner = upper('&thisuser')
GROUP BY t1.table_name, t1.owner);
PROMPT prompt ~~~ END OF REPORT ~~~
PROMPT spool off
PROMPT prompt your output is in : &thisuser._&thisdb..txt
SPOOL off

SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>SQL*Plus Report</title> -
<STYLE TYPE='TEXT/CSS'><!--BODY {background: ffffc6} --></STYLE>"
SET ECHO OFF
spool &thisuser._&thisdb..html
@tmp_script.sql
SPOOL off
SET MARKUP HTML OFF

[Updated on: Wed, 06 October 2010 12:12] by Moderator

Report message to a moderator

Re: Describing all the tables in a database [message #478212 is a reply to message #374495] Thu, 07 October 2010 02:55 Go to previous message
hem5840
Messages: 3
Registered: October 2010
Junior Member
Excellent! That worked. Many thanks for your help.
Previous Topic: orapwd errors
Next Topic: Database link throws ORA-04052 ORA-00604 ORA-12170
Goto Forum:
  


Current Time: Sun May 19 19:09:33 CDT 2024