How to identify unused tables from the oracle database [closed] - oracle

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I have a production database with 1500 tables. Want to cleanup few tables that are created for testing purpose. Is there any process to identify unused tables.
Note: Auditing is not enabled in the database

You need to take snapshots of v$segment_statistics on a regular basis and then compare the data over time.
Something like:
create table usage_statistics
(
as_of timestamp,
table_name varchar(30),
table_owner varchar(30),
num_logical_reads number,
num_physical_reads number,
num_full_scans
);
Then create e.g. a cron or dbms_scheduler job to run the following
insert into usage_statistics (as_of, table_name, table_owner, num_logical_reads, num_physical_reads, num_full_scans)
select current_timestamp,
object_name,
owner,
sum(case when statistic_name = 'logical reads' then value end),
sum(case when statistic_name = 'physical reads' then value end),
sum(case when statistic_name = 'segment scans' then value end),
from v$segment_statistics
where owner in ('USER_NAME_1', 'USER_NAME_2')
and object_type = 'TABLE'
group by object_type, object_name
order by object_type, object_name;
Of course you will need to adjust the names of the owners you want to monitor.
The above statement only checks for three statistics. Use the view V$SEGSTAT_NAME to see a list of all available statistic names in v$segment_statistics
Then after a while you can compare the changes in the reads for each table.

I started from this:
select table_name, last_analyzed
from user_tables
order by last_analyzed desc;
select table_name, last_analyzed
from all_tables
order by last_analyzed desc;
I ask programmers and I droped the oldest tables.

Related

why inline view is different from other views?what is the use of naming it as a view [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
As i know inline view is not a database object and it is just like writing a sub query in from clause so what is the use of naming it as a view .Simply we can call as a sub query.
It is Oracle naming convention. From Inline View and Subquery:
An inline view is a SELECT statement in the FROM-clause of another SELECT statement. In-line views are commonly used to simplify complex queries by removing join operations and condensing several separate queries into a single query.
This feature is commonly referred to in the MSSQL community as a derived table, and in the Postgres community simply refers to it as a subselect (subselects are inline views + subqueries in Oracle nomenclature).
A subquery (sub-query) is a SELECT statement in the WHERE- or HAVING-clause of another SELECT statement.
So when you used it with FROM it is called inline view:
SELECT *
FROM ( SELECT deptno, count(*) emp_count
FROM emp
GROUP BY deptno ) emp,
dept
WHERE dept.deptno = emp.deptno;
And when you used it with WHERE/HAVING it is called subquery:
SELECT ename, deptno
FROM emp
WHERE deptno = (SELECT deptno
FROM emp
WHERE ename = 'TAYLOR');

Oracle Metadata - How can I get table create date? [duplicate]

This question already has answers here:
How to find out when a particular table was created in Oracle?
(5 answers)
Closed 6 years ago.
Is there any Oracle metadata table that show me the created date from a specific table?
Try this:
select object_name, created
from user_objects
where object_type = 'TABLE'
and object_name = '...'
You can user all_objects or dba_objects instead of user_objects, depending on your privileges and on the users you are interested in

How oracle statement works? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
create table samp
(
empno number(2),
ename varchar2(30),
sal number(7,2),
dob date
)
SQL> /
SQL> insert into samp values(1,'MASTAN',24000,'24-JUL-1987');
1 row created.
here i did not commit data so it is in redo log buffer,but when retrieving , how the below Query giving data? How internally works ?kindly suggest me
SQL> SELECT * FROM SAMP;
EMPNO ENAME SAL DOB
---------- ------------------------------ ---------- ---------
1 MASTAN 24000 24-JUL-87
It seems you did not commit or rollback so you are seeing the correct result from your select statement because it happens in single transaction. Try rollback and check the results. Another good way to understand transactions is to try opening two separate sqlplus shell and trying insert statements in one and select statements in the other shell.

Using temporary table in Stored procedure [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have written stored procedure and it takes long time when i call it.
I use temporary table in 'SP'.
it can be reason ??
CREATE OR REPLACE PROCEDURE TEST_SP
IS
BEGIN
INSERT INTO MYTEMP_table (A, B )
( SELECT id AS CUSTOMER_NO,
ACC_NO AS ACCOUNT_NO
FROM myTable );
UPDATE MYTEMP_table
SET MYTEMP_table.A =
( SELECT MIN (BRH_DATE)
FROM CUSTOMER,)
UPDATE MYTEMP_table
SET MYTEMP_table.B =
( SELECT MIN (SUBSTR (ENTRY_DATE, 0, 8))
FROM INFO)
.......
MYTEMP_table is temporary table.
This code snippet looks woefully incomplete. Seems odd that you are filling the temp table with one query:
select id, acc_no from myTable
and then wiping out all columns with a single value:
UPDATE MYTEMP_table
SET MYTEMP_table.A =
( SELECT MIN (BRH_DATE)
FROM CUSTOMER,)
Your post is not clear, but hopefully you are using a global temporary table (Memory based) rather than a physical table meant for temporary storage.
Multiple writes to the same rows is a sure-fire way of slowing down the works (Much more-so in a physical table, but still slow either way). If possible, consider the following:
Use analytic functions or a more complex initial query to get all your writing done up front...
If you're not comfortable/familiar with running/reading explain plans, try running each SQL statement in a SQL Editor manually to assess their individual performance...

Finding constraints enforced across multiple tables in oracle [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I have a database with the following tables EMP, DEPT, CLIENT and PURCHASE. I am using Oracle 11g express edition
I have executed the following SQL statement to find out constraints on table : EMP
SELECT * FROM USER_CONSTRAINTS WHERE TABLE_NAME = 'EMP'
Is there a way to find out what constraints are currently enforced upon this database across multiple table in one statement?
E.g. EMP AND CLIENT AND etc something like that.
You might try something like
SELECT *
FROM USER_CONSTRAINTS
ORDER BY TABLE_NAME,
CONSTRAINT_NAME
which will let you browse through all constraints in the database. If you've got a subset of tables you're interested in you can toss in a WHERE clause such as
SELECT *
FROM USER_CONSTRAINTS
WHERE TABLE_NAME IN ('EMP',
'CLIENT',
'OTHER_TABLE',
'OTHER_TABLE2',
'YET_ANOTHER_TABLE')
ORDER BY TABLE_NAME,
CONSTRAINT_NAME
or
...
WHERE TABLE_NAME = 'EMP' OR
TABLE_NAME = 'CLIENT' OR
TABLE_NAME = 'OTHER_TABLE' OR
TABLE_NAME = 'OTHER_TABLE2' OR
TABLE_NAME = 'YET_ANOTHER_TABLE'
...
The two WHERE clauses above are equivalent - the first is just a bit more compact.
Share and enjoy.

Resources