primary key for a table with only 1 column
I create a temporary table in my procedure and there is only a single column in it. I'll eventually use this temporary table in a join. Does make sense to create a primary key for this temporary table? It will make my join run faster? In other words, oracle automatically sorts and keeps the table column is the fact that if a primary key or index is created? I use 10g - 10.2.0.3.0The data table is not indexed.
Oracle will probably make a hash join.
Have you tried just current execution Plan for your query to explain?
Hemant K Collette
http://hemantoracledba.blogspot.com
Tags: Database
Similar Questions
-
How to add the primary key for the table with the existing data?
The table is already busy data. There was no primary key before, so for each column, there are some duplicate values.
I want to add a new column, which should be of the integer data type and can automatically incremented, from 001. I tried with Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column. How can I do? Thank you!Hello
Look for the [ALTER TABLE | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm#sthref4803] command to find out how to add a column (step (1)) and a (step (3)) constraint to an existing table.
For the step (2):
CREATE SEQUENCE employee_id_seq START WITH 1 ; UPDATE employee SET id = employee_id_seq.NEXTVAL;
When you create a sequence, START WITH 1 is the default value, so that the line is not really necessary above... I've included just to show how you could start with any number you have chosen.
-
I have a Gr_order table that was settled long ago, and now he needs to be filled
with some more search data.
"Orderid" is a primary key for the table, but the question is how can I insert "orderid" in the insert statement in the procedure. I couldn't find any name sequence. There are 1230
documents that must be inserted.
Desc Gr_order Orderid Number Primary key Desc Varchar2
Thank youINSERT INTO gr_order (orderid,desc) VALUES (???, upper(each_pom.desc);
SandyYou can find the code that inserts into the table and see if it uses the sequence ;-). A sequence is not 'attached' to a particular table - this is the insert statement to determine whether a sequence should be used.
You can check if the table has a trigger - some developers like to emulate the behavior of MS - sql server by having a trigger on the table that selects in a sequence. If it has such a release, then you just do your insertions without specifying order_id. But if the table does not have such a release, then you cannot know if the table was originally filled using a sequence or not (unless you can find the instructions for inserting somewhere).
-
Two constraints of primary key of a table with two different constraint name
Hi guys
I am creating the table below
Table name: TITLE_COPY
Column name Copy_id Title_id Status Key type
PK PK, FK Unique NN, U NN, U NN Check Available, destroyed, leased, reserved Table Ref FK Title FK Ref Col Title_id Data type Number Number Varchar2 Length 10 10 15 The SQL statement below can create it
CREATE TABLE title_copy (copy_id NUMBER (10),)
title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.
primary key constraint title_copy_title_id_pk title_id (copy_id)
status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))
);
Two primary keys (title_id, copy_id) are created with the same name of constraint (title_copy_title_id_pk) (-> table-level constraint). What happens if I want to have two different names of the primary key constraint, say title_copy_title_id_pk for the title_id column and title_copy_copy_id_pk for the copy_id column?
I can do that with a column-level constraint? Something like below (complains about the additional primary key)
CREATE TABLE title_copy (copy_id NUMBER (10) CONSTRAINT title_copy_copy_id_pk PRIMARY KEY,)
constraint title_copy_title_id_pk primary key (title_id).
title_id CONSTRAINT NUMBER (10) title_copy_title_id_fk title (title_id) REFERENCES.
status VARCHAR2 (15) NOT NULL CONSTRAINT status_ck CHECK (status IN ('AVAILABLE', 'DESTROYED', 'RENTAL', 'RESERVED'))
);
In summary, I can define two primary keys with the name of different constraint in a column-level constraint?
There are no two primary keys. There is a primary key made up of two columns - also called a composite key.
A table can have at least a primary key. You can, if you wish, create a unique constraint on a different set of columns.
-
How to define a Composite primary key for a Table
Hello
I'm basically more in Java programming, with little knowledge of Oracle bit as DataBase .so please sorry for my silly doubts.
Can someone tell me please how to define a Composite primary key on a Table.
Thanks in advance.
Published by: user672373773 on 25 Sep, 2009 08:54Please go through these links:
http://plsqlworld.blogspot.com/2009/01/oracleplsql-composite-primary-key.html
http://sqlzoo.NET/HOWTO/source/z.dir/tip241027/Oracle
Concerning
Asif Kabir-Mark the response as correct/good
-
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 -
Change of primary key on the Table clears the other columns
Preliminary info/Installation
JDeveloper 11 g 11.1.1.6.0
We have a table (object view or entity) that has 8 columns. The primary key is composed of 4 1 columns.
The table is displayed in a page fragment.
2 of the 4 non-primary key columns are LOV.
All the 8 columns are needed.
The table is editable including 2 of primary key columns.
Question
Assume that the table displays the 3 lines. If we change a rank 1 non-primary key column and a primary key in row 2 column, everything works well when we are committed to the database
If, however, we first change a primary key column, then a primary key on a different line column, then the column/row primary key that changed us first, gets annihilated and the other columns LOV on this same line. The 2 columns that are not LOV keep data as it should. We then get a validation error because the required data are not present. All this happens before we try all commit to the database. If debug us and look the iterator, it has the old data in this document, before and after any performance on the binding.
If we look at and update the data via the App Module, everything works well. We have tried to update the view, etc. through valueChangeListener also with no luck.If you change the primary key value, it should not be the primary key.
This is true in the design of database relational regardless of how access you the data. In addition, EO don't like if you change the primary key value.
Have you considered adding a surrogate key (use a sequence) and make your PK course a unique key?
John
-
Why we cannot create more than one primary key on a table. Why we create several unique key on a table. Please explain if anyone have details of this.
«a primary key has semantic meaning, it is to be immutable (never change of value), unique and not null.»
a unique constraint is simply "at any time, these values are unique - they can change and they can be null.
You use a unique when constraint
(a) you do not already have a primary key for a table can have only one
(b) you allow NULL values in attributes
"(c) to allow you to update the values in the attributes.https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:5541352100346689891
-
primary key for a column made up of duplicates
Hello
-> I have created a table and
-> I have a column consisting of 1,000 records (but where I have duplicates)
and now, I want to create a primary key for the column
How can I do it...Hello
Run the utlexcpt.sql script located in the ORACLE_HOME/rdbms/admin directory level to create the exception table.
Thank you
-
a key for the table does not exist in the table
Hi guys,.
I imported several tables of physical layer in the administration tool. So, I want to do new foreign key between tables join in the physical schema.
Required fields for posting a link between these tables are set up. When I press the ok button, an error message is displayed:
"a key corresponding to the table does not exist in the table blablabla. You want to create a? »
In fact, what is this error? I don't have all the idea about it. The number of the type of the fields is the same, the names are also the same. I think that he should not have problems to make the new foreign key. But why is it happening?
Thank youHello
It is the primary key of the first table. You might not have set this column as the primary key of this table at the level of the db.
Thank you
Imtiaz. -
Two foreign keys of a table in a single column
Hi gurus
I wonder that can we add two foreign keys of a table on a single column, I think the answer is, but what should be the reason behind this?
Appreciate if someone there explain to me...
Concerning
Muzz
Hello Muzz,
Perhaps the example of human Chen reveals a design error.
If a student has a 'teacher_id' "teacher" FK and FK for "emp" becaue each teacher is an EMP, I guess that the correct design would be to have only the FK of 'teacher' and to have another pointing to the 'emp' table in the 'teacher' tabe FKBut we can imagine comical situations...
CREATE TABLE PEOPLE (id NUMBER of KEY PRIMARY, name VARCHAR2 (20 CHAR),...);
CREATE TABLE SCIENTIST (id people KEY PRIMARY NUMBER (id) REFERENCES, discipline VARCHAR2 (20 CHAR),...);
CREATE TABLE POLICEMAN (id REFERENCES to KEY PRIMARY NUMBER (id), hire_date people DATE,...);First table = all.
2nd: a subset of the first, with people having the profile of 'scientific '...
3rd: a subset of the first, with people being a policeman.
It might be people first table and in none of the 2nd and 3rd, 1st and 2nd, 1st and 3rd only or in the 3 tables.Then we can have a fourth table of 'something' referring to a person who must be a scientist and a police officer.
Here is a sqlplus session illustrating; the last piece: I try inserting several lines in xxxx, only the last is accepted.
SQL > CREATE TABLE PEOPLE (id NUMBER of the PRIMARY KEY, name VARCHAR2 (20 CHAR));
Table created.SQL > CREATE TABLE SCIENTIST (people of REFERENCES of KEY PRIMARY NUMBER id (id), discipline VARCHAR2 (20 CHAR));
Table created.SQL > CREATE TABLE POLICEMAN (people of REFERENCES of KEY PRIMARY NUMBER id (id), DATE hire_date);
Table created.SQL > CREATE TABLE XXXX (id PRIMARY KEY NUMBER, people_id NUMBER, any other VARCHAR2 (30 CHAR));
Table created.SQL > ALTER TABLE ADD CONSTRAiNT fk_xxsci FOREIGN KEY (people_id) scientific xxxx REFERENCES (id);
Modified table.SQL > ALTER TABLE ADD CONSTRAiNT fk_xxpol FOREIGN KEY (people_id) police xxxx REFERENCES (id);
Modified table.SQL > INSERT INTO person VALUES (100, 'John');
1 line of creation.SQL > INSERT INTO person VALUES (120, 'Mary');
1 line of creation.SQL > INSERT INTO person VALUES (103, 'Tom');
1 line of creation.SQL > INSERT INTO person VALUES (123, "Bruno");
1 line of creation.SQL > INSERT INTO VALUES of scientific (120, 'Chemistry');
1 line of creation.SQL > INSERT INTO scientific VALUES (123, 'Mathematics');
1 line of creation.SQL > INSERT INTO VALUES of policeman (103, DATE ' 2001-04-01');
1 line of creation.SQL > INSERT INTO VALUES of policeman (123, DATE ' 1998-07-01');
1 line of creation.SQL > INSERT INTO xxxx VALUES (1, 456, "nothing");
ERROR on line 1:
ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not foundSQL > INSERT INTO xxxx VALUES (1, 100, "only to people");
ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not foundSQL > INSERT INTO xxxx VALUES (1, 120, "only the learned");
ORA-02291: integrity constraint (SYS. FK_XXPOL) violated - key parent not foundSQL > INSERT INTO xxxx VALUES (1, 103, "only police officer");
ORA-02291: integrity constraint (SYS. FK_XXSCI) violated - key parent not foundSQL > INSERT INTO xxxx VALUES (1, 123, 'ok');
1 line of creation.Best regards
Bruno Vroman.
-
How to create a table with two unique columns
How to create a table with two unique columns. I use the following syntax below and I get the error message such unique or primary key already exists.
create the table COPQ_WORKCELL_GOAL
(
Type_id varchar2 (4) NOT NULL UNIQUE,
Tyle_Location varchar2 (30) NOT NULL UNIQUE,
Type_Description varchar2 (20).
KEY elementary SCHOOL (Type_id)
);Use 1 or the other column type_id;
create table COPQ_WORKCELL_GOAL ( Type_id varchar2(4), Tyle_Location varchar2(30) NOT NULL UNIQUE, Type_Description varchar2(20), PRIMARY KEY (Type_id) ); Table created drop table COPQ_WORKCELL_GOAL; Table dropped create table COPQ_WORKCELL_GOAL ( Type_id varchar2(4) primary key, Tyle_Location varchar2(30) NOT NULL UNIQUE, Type_Description varchar2(20) ); Table created
-
Importing data with impdp table with 3 new columns
Hello
Is it possible to import data with impdp in tables with 3 new columns?
Kind regards
William
To do this, I use this method:
Add the three columns in the source table and create the package:
CREATE OR REPLACE PACKAGE DATAPUMP_TECH_COLS
IS
FUNCTION SET_DML_DATE (p1 in TIMESTAMP)
BACK TO TIMESTAMP;
FUNCTION SET_DML_TYPE (p2 in VARCHAR2)
RETURN VARCHAR2;
FUNCTION SET_DML_SCN (p3 in NUMBER)
RETURN NUMBER;
END DATAPUMP_TECH_COLS;
/
CREATE OR REPLACE PACKAGE BODY SYS. DATAPUMP_TECH_COLS
IS
FUNCTION SET_DML_DATE (p1 in TIMESTAMP)
RETURNS THE TIMESTAMP
IS
BEGIN
SYSDATE RETURN;
END;
FUNCTION SET_DML_TYPE (p2 in VARCHAR2)
RETURN VARCHAR2
IS
BEGIN
RETURN ' ';
END;
FUNCTION SET_DML_SCN (p3 in NUMBER)
RETURN NUMBER
IS
BEGIN
RETURN 0;
END;
END;
/
Export a table with remap_data
expdp = TEMP_DIR PARALLEL = 8 TABLES directory is PIVOTMAT2. ACCTG_LINE LOGFILE = expdp_acctg.log = COMPRESSION STATISTICS ALL EXCLUDE =.
DUMPFILE = ACCTG1.dmp, ACCTG2.dmp, ACCTG3.dmp, ACCTG4.dmp, ACCTG5.dmp, ACCTG6.dmp, ACCTG7.dmp, ACCTG8.dmp REUSE_DUMPFILES = YES.
REMAP_DATA = PIVOTMAT2. ACCTG_LINE. DML_TYPE:SYS. DATAPUMP_TECH_COLS. SET_DML_TYPE.------
REMAP_DATA = PIVOTMAT2. ACCTG_LINE. DML_DATE:SYS. DATAPUMP_TECH_COLS. SET_DML_DATE.------
REMAP_DATA = PIVOTMAT2. ACCTG_LINE. DML_SCN:SYS. DATAPUMP_TECH_COLS. SET_DML_SCN
Import table
Impdp "" / as sysdba "" DIRECTORY = SRC_PIVOT TABLE_EXISTS_ACTION = TRONQUER REMAP_SCHEMA = PIVOTMAT2:STGPIV.
DUMPFILE = ACCTG1.dmp, ACCTG2.dmp, ACCTG3.dmp, ACCTG4.dmp, ACCTG5.dmp, ACCTG6.dmp, ACCTG7.dmp, ACCTG8.dmp PARALLEL = 8
to complete the removal of the collar if necessary.
-
Hi guys,.
I had a simple order form when you add products.
So I had 2 tables, ORDER (order_id, order_date) and ORDER_ITEMS (order_id, product_id, product_qty)
My ORDER_ITEMS are added through tabular form
I can't create a 1 time order, as I create the ORDER first to get the primary key to add to ORDER_ITEM. I tried the Return key in point and placed the DML above the ApplyMRU process. But no luck.select * from ORDER_ITEMS WHERE ORDER_iD = :P21_ORDER_ID;
THE P21_ORDER_ID is display only save session state.
Bit at a loss how to create both and to order and add its items in a single time instead of creating the order first then order items. Anyone know how I can accomplish this?
Return key point seems to be the solution for this but I can't get it to work. Thank you very much.Take a look at your request, I changed the driver to the new process page, products and create an order which returns the primary key. Now you can create the initial product registration with in the process. do not disable the multirow process that always allows you to add or update records.
-
How to specify the tablespace for a India primary key in create table statement
How to specify the storage space for a primary key index in a create table statement?
Does the following statement is true?
Thank youCREATE TABLE 'GPS'||TO_CHAR(SYSDATE+1,'YYYYMMDD') ("ID" NUMBER(10,0) NOT NULL ENABLE, "IP_ADDRESS" VARCHAR2(32 BYTE), "EQUIPMENT_ID" VARCHAR2(32 BYTE), "PACKET_DT" DATE, "PACKET" VARCHAR2(255 BYTE), "PACKET_FORMAT" VARCHAR2(32 BYTE), "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP, CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") TABLESPACE "INDEX_DATA" ) TABLESPACE "SBM_DATA";
Published by: qkc November 9, 2009 13:42As orafad noted, you can use the documentation using ESCALATION clause, i.e.
SQL> ed Wrote file afiedt.buf 1 CREATE TABLE GPS 2 ("ID" NUMBER(10,0) NOT NULL ENABLE, 3 "IP_ADDRESS" VARCHAR2(32 BYTE), 4 "EQUIPMENT_ID" VARCHAR2(32 BYTE), 5 "PACKET_DT" DATE, 6 "PACKET" VARCHAR2(255 BYTE), 7 "PACKET_FORMAT" VARCHAR2(32 BYTE), 8 "SAVED_TIME" DATE DEFAULT CURRENT_TIMESTAMP, 9 CONSTRAINT "UDP_LOG_PK" PRIMARY KEY ("ID") USING INDEX TABLESP ACE "USERS" 10 ) 11* TABLESPACE "USERS" SQL> / Table created.
Justin
Maybe you are looking for
-
Satellite PRO L20: Tools & Utilities CD-ROM refuses to install the audio driver
Tools & Utilities CD refuses to install the audio driver on my system (Satellite PRO L20). No idea how to solve this problem?
-
Exapnd eMachines with AMD x 86-64 Semperon le-1200 RAM
Original title: AMD x 86-64 Semperon le-1200. The motherboard is the gateway is Sempron le-1200 is x 86-64 bit, AMD socket AM2 940 on eMachines W3644. Is it possible that eMachines W3644 can adapt it to 3 GB or 4 GB for a loan of 64-bit? Since then,
-
Error code 80070026 Windows Update
Remember - this is a public forum to not publish any private information such as phone numbers or e-mail! Ideas: When the update security for Windows 7 pour computer processor x 64 (KB2393802) several times = nominal code 80070026 failed WITH error W
-
calendar of implementation pilot
I'm still waiting for the scanner to my officejet 4355 driver & waiting is irritating. HP will come out a timetable for implementing pilot? so that we won't have to keep wondering.
-
All-in-one j6480 using linux, problems during the update of the kernel
I have a platform of linux opensuse 11.0 (printer was working fine before the update) and updated the linux kernel and lost the connection to a printer, is the hpj6480 all-in-one printer, then updated to hplip 3.9.2 using auto-install in the terminal