Oracle Identity columns system generated sequence life cycle [duplicate] - oracle

This question already has answers here:
cannot drop a system-generated sequence
(2 answers)
Closed 7 months ago.
I created a table with identity column and which created system generated sequence. On dropping the table which is not dropping the sequence. When the system generated sequence will be dropped? Please help to understand.
SELECT object_name, object_type
FROM user_objects where object_type ='SEQUENCE'
CREATE TABLE identity_test_tab (
id NUMBER GENERATED ALWAYS AS IDENTITY,
description VARCHAR2(30)
);
which created system generated sequence ISEQ$$_131916100
drop table identity_test_tab;

If you drop table, SEQUENCE won't get dropped. You need to dropped it separately.
Drop sequence sequence_name;
The above command give you error. You can use.
purge recyclebin;
Second Answer
You can find these kinds of Identity sequence with below query.
SELECT *
FROM user_objects where object_type ='SEQUENCE' and generated='Y' order by last_ddl_time desc;

Related

How to get comments for table & column from oracle DB from its metadata?

I am working on a Java Application. I have connected to an Oracle DB using JDBC Connection and fetched it metadata. I am fetch information like tables, columns, views, etc from its metadata.
Now I want to fetch Comments for tables and columns separately in the application from metadata.
How can I fetch this details?
Now I want to fetch Comments for tables and columns separately in the application from metadata. How can I fetch this details?
For table comments, use [DBA|ALL|USER]_TAB_COMMENTS view.
Example:
SQL> SELECT table_name,
2 comments
3 FROM dba_tab_comments
4 WHERE owner ='OE'
5 AND table_name='INVENTORIES';
TABLE_NAME COMMENTS
----------- ---------------------------------------------------------------
INVENTORIES Tracks availability of products by product_it and warehouse_id.
For column comments, use [DBA|ALL|USER]_COL_COMMENTS view.
SQL> SELECT table_name,
2 column_name,
3 comments
4 FROM dba_col_comments
5 WHERE owner ='OE'
6 AND table_name='INVENTORIES';
TABLE_NAME COLUMN_NAME COMMENTS
----------- -------------------- ----------------------------------------------------------------------------
INVENTORIES PRODUCT_ID Part of concatenated primary key, references product_information.product_id.
INVENTORIES WAREHOUSE_ID Part of concatenated primary key, references warehouses.warehouse_id.
INVENTORIES QUANTITY_ON_HAND
SELECT *
FROM user_tab_comments;
SELECT *
FROM user_col_comments;
You can also use all|dba prefix instead of user.
Try dbms_metadata package. With it you can extract comments, grants and other things from db.
SELECT DBMS_METADATA.GET_DEPENDENT_DDL('COMMENT','TABLE_NAME','SCHEMA') FROM DUAL
if the other answers didn't work you should probably try:
Retrieving comments from tables and views
SELECT * FROM ALL_TAB_COMMENTS
Retrieving comments from Columns
SELECT * FROM ALL_COL_COMMENTS
This worked for me in an Oracle-RDS (AWS).

Give name to existing constraint without dropping [duplicate]

This question already has answers here:
How to ADD a CONSTRAINT NAME to an already EXISTING CONSTRAINT
(2 answers)
Closed 5 years ago.
I'm learning ORACLE and create a table with different columns and constraint, Now I want to give a name to already created constraint without dropping the constraint. How I can give name to them? as I see there are couple of constraints in user_constraints table, but I don't know their name like(null, unique) and their column.
Again I want to give name to my existing constraints(which have default oracle created name like ( SYS_C0010392 ).
Here is query image that I used to create table with constraints.( SQLPLUS not allowing to copy the query that's why I add image )
ALTER TABLE dept RENAME CONSTRAINT SYS_C0010392 TO new_name;
And SQL*Plus is console application as any other so you definitely can copy selected text.
Column CDB/DBA/ALL/USER_CONSTRAINT.CONSTRAINT_TYPE describes the constraint type, see http://docs.oracle.com/cloud/latest/db121/REFRN/refrn20047.htm#REFRN20047.
Constraint name can be specified in CREATE TABLE command:
create table my_table (
col1 number
constraint my_table_col1_nn not null
constraint my_table_col1_uq unique
);
Column constraint association is available in CDB/DBA/ALL/USER_CONS_COLUMNS:
SELECT * FROM ALL_CONS_COLUMNS WHERE CONSTRAINT_NAME = 'SYS_C0010392'

oracle database to find recently added column in table or database(oracle)

I want to find the recently added column to existing table.
How to find recently added column in table or database(oracle).
Recently the table and the databases of our web application got modified and some of the table got altered.
Ideally you should have restricted access to your Production database, together with a build process which applies scripts out of source control, rather than allowing people to change things using TOAD. It's pretty hard to conduct forensics in a free-fire zone.
You can find out which tables have changed by interrogating the data dictionary:
SQL> select object_name from user_objects t
2 where t.object_type = 'TABLE'
3 and t.last_ddl_time > trunc(sysdate)
4 /
no rows selected
SQL> alter table t23 add col_3 number
2 /
Table altered.
SQL> select object_name from user_objects t
2 where t.object_type = 'TABLE'
3 and t.last_ddl_time > trunc(sysdate)
4 /
OBJECT_NAME
----------------------------------------------------------
T23
SQL>
This won't tell you what the change was, or who did it. To get better information you need a proper audit trail. At the very least you should enable auditing of DDL statements....
SQL> audit ALTER TABLE;
Audit succeeded.
SQL>
Find out more.

Table not created in specific tablespace - Oracle

I am a moderate user of Oracle and I had to create some of the tables in specified table space as shown below.
create table t_abc tablespace abc_tbspc as select * from abc;
create table t_xyz tablespace abc_tbspc as select * from xyz;
After running these through jobs (file containing around 5 tables to be created in a single tablespace), I could see that the table t_abc is created in abc_tbspc ; but the table t_xyz is assigned to null when I query the all_tables. Not sure why the 2nd table is not created in the specified tablespace even though there is abundant space in the table space.
TABLESPACE_NAME will be null for one of these reasons:
Temporary Temporary tables use a temporary tablespace.
Index Organized Index-organized tables store data in an index, not in a heap.
Partitioned Each partition could have a different tablespace, there is not necessarily one tablespace for the whole table.
External External tables do not store their data in a tablespace.
Your code should not meet one of the conditions above; did you leave out some details? I ran the query below to look for other cases where TABLESPACE_NAME is null but could not find any.
select *
from dba_tables
where tablespace_name is null
and (temporary is null or temporary <> 'Y') -- #1
and (iot_type is null or iot_type <> 'IOT') -- #2
and (partitioned is null or partitioned <> 'YES') -- #3
and (owner, table_name) not in -- #4
(select owner, table_name from dba_external_tables)

How to find out that an Oracle Table Partition is a System Generated Partition?

Am creating an Oracle HASH Table Partitions by using the below query
CREATE TABLE Table1 (
ID NUMBER, NAME VARCHAR2(50))
PARTITION BY HASH (ID)
PARTITIONS 25
STORE IN (Tablespace1);
Which Creates 25 HASH table partitions and also, the Database generates the 25 Unique partition names like SYS_P122, SYS_P123, SYS_P124... and so on for the partitions. Is there a way to find out this Partition lets say SYS_P123 is a system generated Partition name with the help of Oracle Catalog tables.
With the below link
http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_2096.htm#REFRN20281
I could find the Oracle Table Partition information, but this catalog table does not have any value to say that the give Table Partition is a system generate or not. Is there any way to find out the given table partition name is system generated ?
Am using Oracle version 10 and 11.
Thanks,
Ravi,
Yes. The generated column in dba_objects gives the information.
Run the following query -
select owner, object_name, subobject_name, generated from all_objects where object_name = 'TABLE1' and object_type = 'TABLE PARTITION';
View the description for the 'generated' column in the following link - http://docs.oracle.com/cd/B28359_01/server.111/b28320/statviews_1145.htm#REFRN20146

Resources