Find tables without primary keys
DB version: 10g Release 2We have several tables that do not have a primary key.
I need to use USER_CONSTRAINTS view to find which of these tables that do not have a primary key.
The following query will not work because there obviously returns all records where CONSTRAINT_TYPE! = « P »
select table_name from user_Constraints WHERE constraint_type != 'P'
I need to jump those table_names who have at least one occurrence of CONSTRAINT_TYPE = 'P '.
Select table_name from user_tables where table_name
not in
(
Select the table table_name from user_constraints where constraint_type = 'P '.
)
Tags: Database
Similar Questions
-
You would design Tables without primary key?
If you were asked to design a schema, if you create a table (however irrelevant) without a primary key? For example, a 'unprofessional' table such as a logging of errors table that records exceptions thrown from stored procedures, create you this table without a primary key?In a relational database you define und work with entities (tables) and you put in relationship to each other by joins. An entity must by definition always be identified by a unique key.
If you don't know what kind of unique key identifies your entries in the table, it is almost certain that working from home in your datamodel and table designs had not been made. Your database objects contain tables, and they must have a unique identifier. Often it is a primary key (PK) composed of several columns.By definition a datamodel that contains the tables without primary keys is nomore a relational datamodel and one of the fundamental bases for the creation of a relational database is violated.
Frankly I do not understand why Oracle allows the tables without primary key. Another system such as SAP R/3 are more stringent. Primary keys are required in the SAP and believe, when starting, it is sometimes tedious to define the primary key structures, but it's the basis of designing together relational datamodel you will put in place. You now SAP is based often on a DB ORACLE layer. They could do it, and these "extend" their functionality. But they are smart guys in Walldorf, and they always refrained to do. It's a good guess to believe, they have a good reason for it.
Tables without primary key are NO relational tables, they are dungpiles. As Oracle needs priimary key itself in order to operate a relational database, ROWID have been defined. ROWID is the primary keys of the tables where the customer does not have a PK. But nice as ORACLE is, they strongly recommend not to use these ROWID in the application or database layer. ROWID is no identifier object that are stable in time and space (eg. two different databases in a distributed design oder a DEV and PROD-system).
Definition of PK implies certain rules for the programming of your application and your DML operations. Especially you often MERGE in a relational table instead of simply INSERT'ing piece in a dungpile.
When it later on with SELECT large datavolumes dataaccess, again the differences between well-defined joins (all based on the PK-relations) and joins non-unique keys will be the order of magnitude. Not only that, the latest degrades in performance much more quickly with the growth of result sets. When you start fumbling with no UNIQUE INDEXES, speed up performance in the operations of dungpiling you are already closer to hell than on a sunny day in the world of relational data.
Othmar Lippuner
SQL Reporting professional -
Get 2 amounts of 2 columns of 2 tables without primary key
I would like to get the sum of column A of table 1 and the sum of column D in table 2 without using the primary key.
Because I can't link the two tables, the only corresponding value is not the primary key.
TABLE 1
COLUMN A. COLUMN B | COLUMN C
PAID NUMBER DESCRIPTION
15472 blabla1 S15-875
18515 S15-875 blabla1 215526.52 blabla2 D17-517
... ... ...
TABLE 2
COLUMN D | COLUMN E | COLUMN F
INVOICE NUMBER DESCRIPTION 185525 blabla1 S15-875
158520 D17-517 blabla2
8964 D17-517 blabla2
I would like to see the number, the sum of which should be paid and what has been paid.
But as you can see, you can pay in several times and there may be several invoices.
There is therefore no link between two tables which is a primary key in both entities.
No idea how I could get it?
NUMBER | DESCRIPTION | BILL | PAID
S15-875 185525 33987 blabla1
D17-517 blabla2 167484 215526.52
The tables can be attached on «NUMBER», regardless of weather conditions, as a primary key is defined.
sql> with table_1 as 2 ( select 15472 as paid, 'S15-875' as "NUMBER", 'blabla1' as description from dual 3 union all select 18515 as paid, 'S15-875' as "NUMBER", 'blabla1' as description from dual 4 union all select 215526.52 as paid, 'D17-517' as "NUMBER", 'blabla2' as description from dual 5 ) 6 , table_2 as 7 ( select 185525 as invoice, 'S15-875' as "NUMBER", 'blabla1' as description from dual 8 union all select 158520 as invoice, 'D17-517' as "NUMBER", 'blabla2' as description from dual 9 union all select 8964 as invoice, 'D17-517' as "NUMBER", 'blabla2' as description from dual 10 ) 11 select t1."NUMBER" as "NUMBER" 12 , t1.description as description 13 , ( select sum(t2.invoice) from table_2 t2 where t2."NUMBER" = t1."NUMBER" ) as invoice 14 , sum(t1.paid) as paid 15 from table_1 t1 16 group by t1."NUMBER" 17 , t1.description 18 / NUMBER DESCRIP INVOICE PAID ------- ------- ---------- ---------- D17-517 blabla2 167484 215526.52 S15-875 blabla1 185525 33987
BTW: 'NUMBER' is a horrible name for a column. I strongly recommend to change something that is not a reserved word.
-
Potential problems for tables without primary keys and unique keys
GoldenGate 11.2.1.0.3/Solaris 10
DB: Oracle for Oracle (Source and target is 11.2.0.3)
Topology: unidirectional
In our one-way configuration GG, little of the tables being replicated is not a primary key or a Unique key.
Last week when we have implemented GG for the test, we received warnings for these table below.
Replication seems to work very well for these tables.GGSCI > add trandata WMHS_UD.crtn_dtl 2013-01-12 11:34:33 WARNING OGG-00869 No unique key is defined for table 'CRTN_DTL'. All viable columns will be used to represent the key, but may not guarantee uniqueness. KEYCOLS may be used to define the key. Logging of supplemental redo data enabled for table WMHS_UD.crtn_dtl.
Googling, I think that there may be performance degradation when you replicate tables without PK or the United Kingdom.
But are there other potential problems such as data of a certain kind not replicated to the lack of PK/UK?It really depends on the data.
By default, GG is combining all columns as a virtual primary key but don't no conflict control by default. So when you can be sure that the record you insert into the table is unique, then it will work.
BUT as soon as you insert the same record, which is already inserted, then you will encounter problems.Let me show what happens when you use an initial charge because it makes it easier to describe:
We start at 10:00 the capture for a table. Now, you insert a record at 10:00 in the tables. When you now start an initial charge to 10.02, then check you have inserted in the database to 10.01 will be repeated two times. During the IPL as the initial charge is made to 10.02 and it includes data of 10.01 AND it will be replicated again through the process of capture/replicate. -
Mr President
My worm Jdev is 12.2.1.
I have master tables / details.
I have 2 lines for each PRIMARY KEY = ("VID", "LINEITEM") as below in the Details table.
Please help how to get a button on a jsf page to remove these two lines at a time.
Concerning
So, in your app (data model) module, you have a master relationship / typical retail:
And the relationship between them is based on some ViewLink
Now go to the ViewLink, relationship, accessor.
Take a look at the Destination accessor.
Generate accessor object to check and give a name Acessor
Then go to the master VO, Java and Include accessor, the class generate a display line:
Go to the class view Java generated line, you'll find a method with the name of the accessor of the previous step, in the form of:
public RowIterator getYourDetails...or_whaterever_IsAccessorName..() { }
Now, in the same Java class, write the following Java method:
public void removeDetails(){ RowIterator details = getYourDetails...or_whaterever_IsAccessorName..(); // it is RowIterator over all details Row r = details.first(); while (r != null) { r.remove(); r = details.next(); } }
This method on the Cilent export line Interface:
Finally, pass the data controls and drop this operation on the form as a button...
-
Update a table with primary key
Hello
I have a table called Temp
CREATE TABLE TEMP ( A VARCHAR2 (50 CHAR), B VARCHAR2 (50 CHAR), C VARCHAR2 (50 CHAR), D VARCHAR2 (18 CHAR), E DATE, F NUMBER, G VARCHAR2 (18 CHAR), H FLOAT );
The primary key is the PRIMARY KEY: (A, B, C, D, E, F, G).
I HAVE THE TEMPORARY TABLE 48052365 COUNTY,
HOWEVER I HAVE A REQUIREMENT TO UPDATE WHERE E (COLUMN) IS WEDNESDAY, THE SAME DAY IN MONDAY (I.E., C - 2 TO EXISTING DATE)
Approach;
I CREATED the TABLE TEMP_WED_TO_MONDAY AND SELECTED ALL THE RECORDINGS ELIGIBLE IN CE AND TABLE AND INDEX UNIQUE CREATED on this SUBJECT. TO UPDATE, I WROTE UNDER ANONYMOUS BLOCK.
Number of Tables: TEMP_WED_TO_MONDAY is 46,921,912 and count of total of the table is 48052365
Anonymous block:
DECLARE CURSOR UPDATE_TEMP_DATE IS SELECT A, B, C, D, E, F, G, E - 2 NEW_E FROM TEMP_WED_TO_MOONDAY; TYPE UPDATE_TEMP_DATE_REC IS RECORD ( A VARCHAR2 (50 CHAR), B VARCHAR2 (50 CHAR), C VARCHAR2 (50 CHAR), D VARCHAR2 (18 CHAR), E DATE, F NUMBER, G VARCHAR2 (50 CHAR), NEW_E DATE ); TYPE UPDATE_TEMP_DATE_TBL_TYPE IS TABLE OF UPDATE_TEMP_DATE_REC; UPDATE_TEMP_DATE_TBL UPDATE_TEMP_DATE_TBL_TYPE; BEGIN OPEN UPDATE_TEMP_DATE; LOOP FETCH UPDATE_TEMP_DATE BULK COLLECT INTO UPDATE_TEMP_DATE_TBL LIMIT 1000000; EXIT WHEN UPDATE_TEMP_DATE_TBL.COUNT = 0; FORALL I IN UPDATE_TEMP_DATE_TBL.FIRST .. UPDATE_TEMP_DATE_TBL.LAST UPDATE TEMP SET E = UPDATE_TEMP_DATE_TBL (I).NEW_E WHERE A = UPDATE_TEMP_DATE_TBL (I).A AND B = UPDATE_TEMP_DATE_TBL (I).B AND C = UPDATE_TEMP_DATE_TBL (I).C AND D = UPDATE_TEMP_DATE_TBL (I).D AND E = UPDATE_TEMP_DATE_TBL (I).E AND F = UPDATE_TEMP_DATE_TBL (I).F AND G = UPDATE_TEMP_DATE_TBL (I).G; COMMIT; END LOOP; CLOSE UPDATE_TEMP_DATE; END;
But for the past 6 hours, it only updated records 20,00,000(Twenty lakh) only. because this update in the table and is also part of the teaching primary key I think it takes time, but pointers to improve/acceleration of the update
Explain the plan:
update statement all_rows (Cost 4) 3 update hr.temp 2 table access by index rowid table hr.temp (Cost 4, Bytes : 64 ,Cardinality 1) 1 index range scan index hr.temp_wed_to_monday (Cost 3: Cardinality 1)
Thank you guys, I would be grateful if someone provides the solution for the scenario, rather than highlight the design. Please understand someone designed to best with whatever the limits it has during this period. (and this isn't me).
-
Great advice table no primary key on the table.
Dear gurus,
Version: Oracle 11.2.0.3.0 running on Linux HAVE 6.
I have a big standard table (400 million lines) which is a data dump, it was created with no primary key Yes crazy but it happens (very rare). I have a few key columns indexed for the purpose of the motion, but I would like to know what are the options I have different indexing on a table to make it more efficient for running a query against it.
Looking for simple opinion where further research. I won't not give an example of the table structure - neither include the details, I'm looking for advice.
Easy points for everyone.
Thank you.
-
Hi all
Is im using jdeveloper 11g possible to use EJB to a table that does not have primary key contain?
TNX,
AzzaielHello
Have a look here: http://www.jguru.com/faq/subtopic.jsp?topicID=126500
You can set the PK of the entity
Frank
-
addition of populated table's primary key column
Hi all
I am trying to add a column to a table that is already filled. The column to be added must be the primary key.
As expected, oracle jumped to the top of the error (ORA-01758) of a column NOT NULL cannot be added, unless the table is empty.
A possible way is to create a new temp table and then transfer all current data... rename the temporary table later.
Is there another way to accomplish this?
Thank youHello
As error suggested you cannot add a constraint not null on the new column to the table that is already filled. What else you can do next to you, you have a fairly simple and fast to create a temporary table and moving data?
You can add the new column but null, update the column with values and alter the table of marking column as not null. But your idea of empty temporary table is simple and fast.CREATE TABLE my_objects AS SELECT 'my_new_column' my_new, owner FROM all_objects WHERE ROWNUM < 1; _Not Null_ ALTER TABLE MY_OBJECTS MODIFY(MY_NEW NOT NULL); _Primary key_ ALTER TABLE MY_OBJECTS ADD CONSTRAINT MY_OBJECTS_PK PRIMARY KEY (MY_NEW);
Concerning
-
exp/imp with sequential primary key table.
Hello
I have a general question about EXP/IMP a table with primary key sequence. I need exp rows in this table of 11g DB and their imp to 9i DB. This table is the same on 11g and 9i. Table 11g is updated daily. I want to import lines which are the only new records to 9i to expedite the process. As this main table of the key is sequential, I intend to export with where table_key > N, N is the max of last importing table_key and then proceed to import on this dump file. Don't you see any problem doing it this way?
Your expertise is greatly appreciated!Hello
I have no problem at all.
If you do not forget to use the 9i export tool, then you should be OK
Also a full table export and import with ignore = Yes will ignore the records that violate the primary key and import only new records.
However, it is not a very clean way to do it.Success!
FJFranken -
Hello guys,.
I have a question about the primary key in my fact table. In my fact table, the primary key is a combination of 3 different columns, 2 columns are primary keys in dimension tables 2 diff. Is it normal to have a primary key in a table of facts, which is a combination of 3 different columns. If yes then when us will be important to the OBI tool only 3 columns Phy layer appears as the PK. should I do the other 2 columns as the PK in the physical layer of the OBI tool or can I leave it as it is. Please let me know
Thank you.I did as you asked me to. Can you let me also know what will happen if I do only a single key as PK and let them other 2 touch as it is. This will affect performance in > is it possible or will I get incorrect values?
No, this will not affect anything, in any case explicitly will give you joined him again in the physical layer.
But it is advisable to show the key columns in the physical layer of the RPD.Thank you
Vino -
DB sequence for the primary key
Hello
I have Table of key primary we use DB sequence in the database itself, for example if start a line (using sql client) DB without primary key sequence will do it for me, because of this trigger.
(1) my doubt is if I generate A EO off this table I need to explicitly set db sequence for this attribute as this or no need to do this sequence bz DB does good for me!
(new oracle.jbo.server.SequenceImpl("SEQ_NAME",adf.object.getDBTransaction())).getSequenceNumber()
-
Dear all,
I have 30 paintings. of which some tables with primary key and the foreign key relationship.
How can I find which table is to have a primary and key to the primary key column, what table is a foreign key for all tables.
Saludos.select a.table_name as parent_table, b.table_name as child_table from user_constraints a,user_constraints b where a.constraint_type='P' and b.constraint_type='R' and a.constraint_name = b.r_constraint_name
-
Difference of path between primary key and a Unique Index
Hi all
Is there a specific way the oracle optimizer to treat differently the Primary key and Unique index?
Oracle Version
Sample data test for Index NormalSQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production SQL>
Examples of test when using primary key dataSQL> create table t_test_tab(col1 number, col2 number, col3 varchar2(12)); Table created. SQL> create sequence seq_t_test_tab start with 1 increment by 1 ; Sequence created. SQL> insert into t_test_tab select seq_t_test_tab.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000; 99999 rows created. SQL> commit; Commit complete. SQL> exec dbms_stats.gather_table_stats(USER_OWNER','T_TEST_TAB',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1565504962 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 | -------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 259 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL> create index idx_t_test_tab on t_test_tab(col1); Index created. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1565504962 -------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | -------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB | 99999 | 488K| 74 (3)| 00:00:01 | -------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL>
If you see here the same even as the statistics were gathered,SQL> create table t_test_tab1(col1 number, col2 number, col3 varchar2(12)); Table created. SQL> create sequence seq_t_test_tab1 start with 1 increment by 1 ; Sequence created. SQL> insert into t_test_tab1 select seq_t_test_tab1.nextval, round(dbms_random.value(1,999)) , 'B'||round(dbms_random.value(1,50))||'A' from dual connect by level < 100000; 99999 rows created. SQL> commit; Commit complete. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab1; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 1727568366 --------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 74 (3)| 00:00:01 | | 1 | TABLE ACCESS FULL| T_TEST_TAB1 | 99999 | 488K| 74 (3)| 00:00:01 | --------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6915 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL> alter table t_test_tab1 add constraint pk_t_test_tab1 primary key (col1); Table altered. SQL> exec dbms_stats.gather_table_stats('USER_OWNER','T_TEST_TAB1',cascade => true); PL/SQL procedure successfully completed. SQL> select col1 from t_test_tab1; 99999 rows selected. Execution Plan ---------------------------------------------------------- Plan hash value: 2995826579 --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 99999 | 488K| 59 (2)| 00:00:01 | | 1 | INDEX FAST FULL SCAN| PK_T_TEST_TAB1 | 99999 | 488K| 59 (2)| 00:00:01 | --------------------------------------------------------------------------------------- Statistics ---------------------------------------------------------- 1 recursive calls 0 db block gets 6867 consistent gets 0 physical reads 0 redo size 1829388 bytes sent via SQL*Net to client 73850 bytes received via SQL*Net from client 6668 SQL*Net roundtrips to/from client 0 sorts (memory) 0 sorts (disk) 99999 rows processed SQL>
* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
Any comments?
Kind regards
BPat>
* In the 1st table T_TEST_TAB, table always use FULL table access after creating indexes.
* And in the 2nd table T_TEST_TAB1, table uses PRIMARY KEY as expected.
>
Yes - for the first table a full table scan will be used as the currently selected column is nullable and indexes do not include null values.The index can be used for the second query, since all the data (first column) is available between the index and there may be no NULL values because of the primary key. If you check constraints, you find that the there is now a CHECK constraint to ensure that the first column cannot be null.
For a full and interesting discussion see the explanation of this and a related issue on the question I ask in this thread
What SYS tables (not seen) contain the value NULL spec /not/ column definition? and my response he posted: 23 April 2012 09:02I ask the question is based on a question here which is similar to yours
Columns becoming nullable after a fall of primary key? -
dependencies of key foreign primary keys
Hi the gems...
I have a table with primary key composite (COL1, COL2)...
create table TABLE1 (COL1, COL2);
ALTER table TABLE1 add the primary key of the constraint (COL1, COL2) PK_TABLE1;
Now, I'm doing another table that will refer to the first table COL1.
create table TABLE2 (COL3, COL4);
ALTER table TABLE2 add constarint FK_TABLE2 (COL3) made reference to TABLE1 (COL1);
but it is a failure "without corresponding unique key or primary' error.You have created a composite primary key, then there must be a composite foreign key that references the composite primary key. You cannot create a foreign key that refers to a unique composite primary key column.
Maybe you are looking for
-
By selecting 'Open in a new tab' right-click menu does nothing
I just updated to firefox 24 on OXS. The right click menu now is meaningless. When I right click on a web link, and select 'Open in new tab', nothing happens. No tab opens. However, I see now countless options irrelevant for that link, such as 'copy
-
Application crashes when connecting remotely for debugging
Hello again all you lovers forum useful! I'm debugging a strange behaviour in my application that does occur on a specific computer in special circumstances. To do this, I have enabled debugging in my application and finally was able to see it as an
-
I'm looking for on what was the original intel cpu in my recently bought elitebook 8560p
I bought an EliteBook 8560p opportunity. How can I know what was the original intel i5. I think that it has been replaced with an i5 2540
-
Hi all, we have a HP Office Jet Pro 8600, running on a Windows 7 Professional (attached USB) Workstation. We found that when a file is scanned into a PDF file of the scanner, it has an option of security enabled by default (see screenshot below). Is
-
After the format of my old PC windows xp sp1 cannot be updated
I just formatted my HP PC. Once I used the original disk to format the PC. Now, my PC looks like new. But I can not activate the automatic updates from microsoft. I'm basically a mechanical engineer. I don't know much about computers. I really surpri