addition of populated table's primary key column
Hi allI 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 you
Hello
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
Tags: Database
Similar Questions
-
How can I update the primary key column
Hello
Can you suggest me best workaround/algorithm for task below:
(Oracle 10g, Solaris OS.)
Location:
Table a primary key column P 'Code', tables children F1, F2,..., reference to F15 "Code_P' foreign key column"P.Code"column, and we do not know which of the child tables data available for a particular value"P.Code.
Task:
Change the value "P.Code" from 100 to 200. So that the result would be that record P [Code = 100] should be updated:
And child tables 'Code_P' column should be updated as:update P set Code = 200 where Code = 100;
The best solution would be that you can easily repeat this task.update F1, F2, .., F15 set P_code = 200 where P_code = 100;
Edited by: CharlesRoos the 28.12.2010 12:10Will there be FK constraints in place?
If so, you may need to modify them so that their application may be temporarily deferred.The gameplan would be something like this:
-Making of CF can be deferred, immediate departure.
-Alter FK set delay.
-Update of Parent table.
-Update of the children tables.
-Immediate constraints set
s ' engage; -
How to find the primary key columns in the tables in MS Access using SQL queries
How to find the primary key columns in the tables in MS Access using SQL queries
Hello
This is the forum for Windows Vista programs related issues.
For better assistance, please try instead the Forums in SQL Server .
Thank you! Vincenzo Di Russo - Microsoft MVP Windows Internet Explorer, Windows Desktop Experience & security - since 2003. ~ ~ ~ My MVP profile: https://mvp.support.microsoft.com/profile/Vincenzo
-
Diagram of all the tables list of primary key column names
Hi people,
I have a Scott user for example, I want to retrieve all tables primary key column names in the user Scott.
can someone help me please.
Thanks in advance,
karmayaYou can log in to SCOTT and try this
select c.constraint_name , cc.table_name , cc.column_name from user_constraints c join user_cons_columns cc on c.constraint_name = cc.constraint_name where c.constraint_type = 'P';
-
How to refer to the primary key column of newly inserted rows of tabular form
Hello
I use APEX 4.2.0.00.27 with Oracle DB 11.2.0.3.0.
I work with a tabular presentation wizard-created for insert and update a table using the integrated SRM process (sequence 10). I'm trying to use a process of anonymous block of PL/SQL (sequence 30) to make another manipulation of table after the records were inserted or updated. The manual process is associated with my tabular form and I use the variables of name of column binding in my program block.
My (rsn_test) table has 3 columns: test_id (number), test_nbr (number), test_id2 (number). Test_id column is identified as the primary key and the type of the source already exists a sequence rsn_test_seq. Column test_id2 gets its default value 0 to a hidden page element.
I would use my manual process for updating the value of the test_id2 column. If it's 0 then I want to put the value of the column test_id. If it is any other value, then it must remain at this value. My logic works very well for an existing line, but I'm running into a problem with the newly added lines. The new lines get inserted, but the test_id2 column remains the default value 0. I can tell the debugger that the SRM process is triggered first and inserts the line, then my manual dealing with fires. The problem seems to be that the connection variable: TEST_ID for the primary key column remains NULL after insertion. I don't know how to get the value of the column test_id of my newly created line to use in my PL/SQL block to my update.
Process of PL/SQL:
DECLARE BEGIN :P7_SHOW := NULL; :P7_SHOW := NVL(:TEST_ID2,555) || ' and ' || NVL(:TEST_ID,787) || ' and ' || NVL(:TEST_NBR,9999); IF :TEST_ID2 = 0 AND :TEST_ID IS NOT NULL THEN UPDATE rsn_test SET test_id2 = :TEST_ID WHERE test_id = :TEST_ID; ELSE :TEST_ID2 := :TEST_ID2; END IF; END;
Excerpt from the debugger:
0.01625 0.00010 Processes - point: ON_SUBMIT_BEFORE_COMPUTATION 0.01635 0.00008 Branch point: Before Computation 0.01643 0.00003 Process point: AFTER_SUBMIT 0.01646 0.00022 Tabs: Perform Branching for Tab Requests 0.01668 0.00008 Branch point: Before Validation 0.01676 0.00024 Validations: 0.01700 0.00135 Perform basic and predefined validations: 0.01835 0.00020 Perform custom validations: 0.01855 0.00049 ...Validation "TEST_NBR must be numeric" - Type: ITEM_IS_NUMERIC 0.01904 0.00007 ......Skip for row 1 because row hasn't changed 0.01911 0.00016 ......Skip for row 2 because row hasn't changed 0.01927 0.00012 ...Validation "TEST_ID2 must be numeric" - Type: ITEM_IS_NUMERIC 0.01939 0.00007 ......Skip for row 1 because row hasn't changed 0.01945 0.00018 ......Skip for row 2 because row hasn't changed 0.01964 0.00005 Branch point: Before Processing 0.01968 0.00004 Processes - point: AFTER_SUBMIT 0.01972 0.00588 ...Process "ApplyMRU" - Type: MULTI_ROW_UPDATE 0.02560 0.00154 ...Execute Statement: declare function x return varchar2 is begin begin for c1 in ( select "RSN_TEST_SEQ".nextval pk from sys.dual ) loop return c1.pk; end loop; end; return null; end; begin wwv_flow.g_value := x; end; 0.02714 0.00140 ......Row 3: insert into "APPPCSRSN"."RSN_TEST" ( "TEST_ID", "TEST_NBR", "TEST_ID2") values ( :b1, :b2, :b3) 0.02854 0.00011 ...Process "ApplyMRD" - Type: MULTI_ROW_DELETE 0.02865 0.00004 ......Skip because condition or authorization evaluates to FALSE 0.02869 0.00015 ...Process "Process Submit" - Type: PLSQL 0.02884 0.00007 ......Skip for row 1 because row hasn't changed 0.02891 0.00012 ......Skip for row 2 because row hasn't changed 0.02903 0.00012 ......Process row 3 0.02915 0.00429 ...Execute Statement: begin DECLARE BEGIN :P7_SHOW := NULL; :P7_SHOW := NVL(:TEST_ID2,555) || ' and ' || NVL(:TEST_ID,787) || ' and ' || NVL(:TEST_NBR,9999); IF :TEST_ID2 = 0 AND :TEST_ID IS NOT NULL THEN UPDATE rsn_test SET test_id2 = :TEST_NBR WHERE test_id = :TEST_ID; ELSE :TEST_ID2 := :TEST_ID2; END IF; END; end; 0.03344 0.00013 ...Session State: Saved Item "P7_SHOW" New Value="0 and 787 and 1300" 0.03356 0.00004 Branch point: After Processing 0.03360 0.00048 ...Evaluating Branch: "AFTER_PROCESSING" Type: REDIRECT_URL Button: (No Button Pressed) Condition: (Unconditional) 0.03407 0.00013 Redirecting to f?p=290:7:8717971109610:::::&success_msg=0%20row(s)%20updated%2C%201%20row(s)%20inserted.Success%2FEBD244168556408CBA714E3974918C09%2F 0.03420 0.00012 Stop APEX Engine detected 0.03432 0.00007 Stop APEX Engine detected 0.03439 - Final commit
Any suggestions?
I have run tests on
https://apex.Oracle.com/pls/apex/f?p=83488:1 demo/demo
to see your problem.
I have 2 solution for your problem.
I add trial NOT tabular just usual block of PL/SQLBEGIN I'm IN (SELECT TEST_ID FROM RSN_TEST WHERE TEST_ID2 = 0) LOOP UPDATE RSN_TEST SET test_id2 = TEST_ID WHERE test_id = i.TEST_ID; END LOOP; END; and works very well, you can see in the sample.
The other solution is to show new generated TEST_ID
Adding a sequence as a default value for a column in a table field
And to execute your procedure.
I get how is with the good luck of time.
By
-
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 -
A composite primary key column cannot be null
Hi all
It will be a silly question, but still, I would like to ask if a composite primary key column can be null?
Thank you
Rafi.Rafi,
Why you think he would be allowed?
SQL> drop table test purge; drop table test purge * ERROR at line 1: ORA-00942: table or view does not exist SQL> create table test as select * from dba_objects; Table created. SQL> alter table test add primary key(object_id, owner); Table altered. SQL> insert into test(object_id, owner) values(null, 'aman'); insert into test(object_id, owner) values(null, 'aman') * ERROR at line 1: ORA-01400: cannot insert NULL into ("SYS"."TEST"."OBJECT_ID") SQL> insert into test(object_id, owner) values(1,null); insert into test(object_id, owner) values(1,null) * ERROR at line 1: ORA-01400: cannot insert NULL into ("SYS"."TEST"."OWNER") SQL>
HTH
Aman... -
How to convert a single column in the primary key column
Hi all
I have a column that's unique cnstraint, this column contains the value as digital and also null.
So how do you convert to primary key column
Concerning
PrashantPrashant wrote:
Hi allI have a column that's unique cnstraint, this column contains the value as digital and also null.
So how do you convert to primary key column
Concerning
PrashantPrashant,
You must assign new values to null values. You can use a sequence to produce the figures in this column.
Select max (your_unique_column) from your_table; -find the maximum value of this column, so you can start the sequence of this number.
create sequence seq_for_your_table with XXXX - value max + 1 you have found
Update your_table set your_unique_column = seq_for_your_table.nextval () where your_unique_column is null
You can create a primary key on this column.
Best regards
Grosbois
-------------------------------------------------------
If you answer this question, please mark appropriate as correct/useful messages and the thread as closed. Thank you -
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.
-
update of a primary key column
Hello
I have a problem I want to expose you for your opinion.
In a table of the source, I have a primary key consisting of four columns (let's call them A, B, C and D).
Columns D must be updated with a different value (a Mappin with another table)
My ODI interface, I set the update keys a, B, C, but of course, it does not work because there is violation of the primary key
I thought, the first value of D in a new column (D_OLD) and use as a 4th update key.
What do you think?
Please suggest me the right way to do it
Thank you for your return
Hello
Maybe I did not understand your problem correctly, but you say that you want to update the value of col D what happens to the part b of your primary key. You cannot update the row using columns A, B and C, because they are not unique. Am I wrong? If this is the case, then how will you identify which line you want to update the value of col D for. Tell if you have 2 lines with the same value for columns A, B and C, and a different value of D so how do you know which line you want to update? If you have the answer to this question, then you should be able to update as well.
Thank you
Ajay
-
Add new ID/Primary Key column with custom ID generation
I use Hibernate as ORM to interact with Oracle.
This issue is no longer on the side of SQL to emulate the generator ID seqHiLo
that we use to generate the primary key for tables, the column ID i.e.
Now I want to add a new column to the ID of an already created table, and this table has data.
I have a procedure to add the ID column in a table:
For example:
ALTER table TableName add (columnName NUMBER);
Then create the sequence
CREATE SEQUENCE SEQ_ID
START WITH 1
INCREMENT BY 1
MAXVALUE 99999999
MINVALUE 1
NOCYCLE;
and after that he use the UPDATE statement to insert some values into the column like this
UPDATE tableName SET columnName is seq_test_id. NEXTVAL
Here I intend to use hibernate_sequence, to be in harmony with the hibernation of generation mode the ID's
The question is:
UPDATE tableName SET columnName = hibernate_sequence. NEXTVAL, generates the ID in the order.
However, I need identifiers according to the algorithm of seqHiLo.
Is there a way to do this in pure SQL?
In short, can we have a personalized way to generate IDS to use in the new column, rather than a sequential,
as stated above?
If you update every row of a session, it won't make any difference if you select from a sequence and use this value immediately (as in your example) or if you go through the algorithm of HiLo: be it you will end up with sequentially numbered lines without leaving space. Then after the update block of existing lines, you will need to create the sequence to be used by your Hibernate application with an initial value of your current value divided by the low value.
If you really want to implement the algorithm of HiLo for the bulk loading, you can of course do so. But it is not necessary: the effect will be the same.
-
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.
-
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. -
How to use a Select list on a second primary key column in a tabular presentation?
Hello
I created a tabular presentation located on the details page of the user (form), that allows to manage roles for this user.
The shape of table contains 3 elements:
-> a checkbox
-> user (PK) column is hidden, and its default value is generated by a function pl/sql (to submit the time), which refers to the element to username.
-> the role of the column is displayed as a named select list LOV: add you a line, choose a role, submit, etc..
But my ROLES table (not created by me...) contains 2 columns: USER and GRANTED_ROLE.
The USER is the primary key, but a user can have multiple roles (= one line per role).
GRANTED_ROLE is the second primary key, so that we can differentiate between one line of another.
At the moment my tabular form has only one primary key (USER), so the GRANTED_ROLE can display as a list select.
But, for this reason, in my opinion, remove the button do not work: all the lines of the user have the same key, so when I select a few lines to remove these, all lines in the form of tables are deleted.
I don't know how my button Delete could recognize the subkey to remove only selected rows...
Or maybe I should use a different type of region?
Thanks for your help!
FannyIn the process of ApplyMRD, try to specify the 'secondary key' column in the section "Source: Multi line Update and Delete"to the second column key in tabular form.»
I have not tested this with your situation, but worth it.
Maybe you are looking for
-
SSL certificate not used for Admin Server connections
I have a GoDaddy SSL certificate installed on OS X Server 10.11.4. It works very well for the web server (https). Connection via Server.app off-site, produces a warning SSL and self-signed certificate. There is a related error regularly in newspapers
-
Re: upgrade memory on the Satellite U200
Where is the memory located on this model that cannot see with any panel removableable? Ta
-
My laptop came pre installed with vista and I wonder if I change to will of xp that any software independent of the current operating system installed?
-
How to change email Windows Live's Hotmail to MSN account?
WANT TO CHANGE MY EMAIL FROM HOTMAIL TO MSN ADDRESS AND DO NOT KNOW HOW DO
-
Behavior of password blackBerry passport photo
Hello It is a question that some experienced users Blackberry device may be able to provide assistance on how the picture behaves BB-logon failed. 1.