Why create a primary key on a VIEW?
One of our developers found that you can define a primary key on a VIEW. What are the circumstances which justify the something like that?-= Chuck
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:636499119911
"
Tom,
I'm a little confused on the constraints on views. According to the documentation, they are not applied. Then
What is the use for the constraints on views?
According to the "SQL Reference": documents
Constraints of view (the view and the column level or attribute) are declarative. It's
Oracle does not apply to them. However, the operations on views are subject to constraints of integrity
defined on the underlying base tables, then you can apply constraints on views through constraints
on the base tables.
Thanks for your time.
Follow-up February 5, 2002-11:00 Central time zone:
They are used for rewriting complex query with other materialized views. It's more "metadata".
-It gives additional information from the optimizer, allows a wider range of the rewrite of the query to
place.
"
Tags: Database
Similar Questions
-
Need to create a primary key by using sequence in a table with records.
Hello
I want to create a primary key for a table that is already having a huge number of records. Am thinking to create the primary key by using a sequence generator. Could someone tell how can I do this using SQL or PL - SQL.
Kind regards
SKHello
Try this...
SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected. SQL> create sequence emp_empno_seq 2 start with 1 3 minvalue 1 4 maxvalue 999999999999999999999 5 increment by 1 6 nocache 7 noorder 8 nocycle; Sequence created. SQL> SQL> ed Wrote file afiedt.buf 1 update emp 2* set empno=emp_empno_seq.nextval 3 / 14 rows updated. SQL> commit; Commit complete. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- --------- ---------- ---------- ---------- 1 SMITH CLERK 7902 17-DEC-80 800 20 2 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 3 WARD SALESMAN 7698 22-FEB-81 1250 500 30 4 JONES MANAGER 7839 02-APR-81 2975 20 5 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 6 BLAKE MANAGER 7839 01-MAY-81 2850 30 7 CLARK MANAGER 7839 09-JUN-81 2450 10 8 SCOTT ANALYST 7566 19-APR-87 3000 20 9 KING PRESIDENT 17-NOV-81 5000 10 10 TURNER SALESMAN 7698 08-SEP-81 1500 0 30 11 ADAMS CLERK 7788 23-MAY-87 1100 20 12 JAMES CLERK 7698 03-DEC-81 950 30 13 FORD ANALYST 7566 03-DEC-81 3000 20 14 MILLER CLERK 7782 23-JAN-82 1300 10 14 rows selected.
Thank you
Prakash P -
Create the primary key on the target
Y at - it no IKM which would create the primary key on target after having read the instructions for the source?
Thank you
Dinesh.Hi Dinesh,
You can customize a KM to create a primary key on the target
The target table will be created with the mention of the primary key constraint in the data target store.Steps: -.
Customiuse creating target step of the table and I create $ step table.
for example: -.
original train target table KM walk (IKM Oracle Simple incremental update): -.
create table< %="snpRef.getTable" ("l",="" "a",="" "targ_name")="" %="">
(
<%=snpRef.getTargetColList("", "[COL_NAME]\t[DEST_CRE_DT] NULL", ",\n\t", "")%>
)custom STAGE: -.
create table< %="snpRef.getTable" ("l",="" "a",="" "targ_name")="" %="">
(
<%=snpRef.getTargetColList("", "[COL_NAME]\t[DEST_CRE_DT] NULL", ",\n\t", "")%>CONSTRAINT constraint_name PRIMARY KEY (< %="snpRef.getColList" ("",="" "[column]",="" ",",="" "",="" "pk")="" %="">)
)Note:- The code above described here is just a sample of reference. I did not test the syntax.
Kind regards
Its -
SQL Data Model 3.0 EA1 trying to create the primary key on OT
Hello
I am trying to change a primary key of a table of the object that has been reversed (imported) from an Oracle 11.2.x RDBMS and get the error message "the incomplete Index Definition. It is displayed in the window "columns transfer Index." I get to the window"properties of primary key 'by pressing the 'Properties' button on the 'table properties'-> 'Primary key'. If I try to change the expression, and then press Ok or apply buttons I get the error. With this be corrected in the production version? That we will be able to create a model in the SQL Developer Data Modeler, which generates a SQL statement similar to the following:
ALTER TABLE x_flags
ADD (CONSTRAINT x_flags_pk PRIMARY KEY (flags.id))
?
Thank you
Scott KHi Scott,.
I am trying to change a primary key of a table of the object that has been reversed (imported) from an Oracle 11.2.x RDBMS and get the error message "the incomplete Index Definition"... With this be corrected in the production version?
Yes
That we will be able to create a model in the SQL Developer Data Modeler, which generates a SQL statement similar to the following:
ALTER TABLE x_flags
ADD (CONSTRAINT x_flags_pk PRIMARY KEY (flags.id))I guess that 'flags' is the type of the object column and 'id' attribute of this type. I logged for this bug, there are however not for 3.0.
Philippe
-
Call a page after you have created a primary key?
Hello
I have a form on a table with a button create on this subject. When I click on the button CREATE and brings back me to this report which shows my new record, the primary key is created. Here, everything's fine.
Now, I want to create a branch to a new page (after treatment), passing the value of my new primary key to this page. But it seems that this value is zero (if I look in the URL there is no value)
For example, I need to create a new customer, then pass the primary key of my client to a new page. But it does not work... someone can help me?
Thank you
MathieuYou should take a look in your SRM process and he'll say
Return key in point
You must put the name of the key (primary) here like this:
P1_PRIMARY_KEY
If you create a new record, the process will get the primary key and set the item with this value. You can refer to this element in your conditional branch and it'll pass this value to your target page. That's essentially what Scott said in his first response.
Denes Kubicek
-------------------------------------------------------------------
http://deneskubicek.blogspot.com/
http://www.Opal-consulting.de/training
http://Apex.Oracle.com/pls/OTN/f?p=31517:1
------------------------------------------------------------------- -
View of Materlized primary key and primary key in the master tables
We use the Oracle 11 g 2 and I created a view on several paintings of master materlized. The paintings of masters all have the primary key, but I understand not all primary key columns in the query definition.
According to Oracle manual e10592
My MV created OK and works. My question is what can be the impact on my MV? Could he hit to performance. It takes 40 minutes to the MV should be created and 5 minutes to refresh the one line insert in each table of mater. I would like to see it refresh in a few seconds.Specify WITH PRIMARY KEY to create a primary key materialized view. This is the default .... The master table must contain an enabled primary key constraint, and the defining query of the materialized view must specify all of the primary key columns directly.
Retrieve the lines of the mview is purely a function of the number of lines and indexing on the mview himself. Mview refreshing at the time of the wall depends on the quality of the query used to refresh the mview. If you include the PKs of the source table in the mview matter or not, here. What matters is the execution of the refresh request path. Is it okay to indexation on the underlying tables to support the joints. Did you use mlog$ _s to allow a quick refresh - mlog$ _s are still usable for your mview. There are a number of possible causes for your problem and we do not have enough information to make an estimate of the problem.
BTW, if the mview could refresh in a few seconds without mlog$ _s, probably unnecessary a mview.
-
creating a unique index of instaed of using the primary key index
Hello
I heard in a debate sometimes it is better to create a unique index on a column and use it instead of using the primary key index in oracle. I did not understand what that the reason propely.
Can someone please help me in this topic if it is valid.
Thanks in advanceOn the surface, which does not seem reasonable... Volume of the DML is irrelevent to determine which column is the primary key for a table.
My wild speculation a bit at a reasonable time could someone do...
If you use synthetic primary keys (i.e. the keys generated by sequence) and that your tables are subject to large volumes of inserts such as there is a danger that the block "to the right" will be the source of contention block and worry not about analysis of beach on the column, you can create a reverse on this column (unique or non-unique) key index before creating the primary key constraint and to indicate Oracle to use this existing index to respect the primary key constraint.
Obviously, however, this involves a lot of assumptions to arrive at a reasonable point. There may well be another set of assumptions that could also lead to a valid argument. Or it could be a myth that someone has heard and just repeats.
Justin
-
Another syntax for creating primary key
Hello
I have a question about the right way to create primary keys.
Earlier, we were on Oracle 9i and we have upgraded to Oracle 10 g. The question is when creating primary key is allowed to create the unique index and then to create the primary key constraint? or directly create the first key is better? or are there ways to both the same?
for example:
one way:
SQL & gt; CONN u2/u2@db1
Connected.
SQL & gt; create table a (a1, b1 varchar2 number (2), the date c1);
Table created.
SQL & gt; create an index on a (a1) tablespace unique pk_a t1;
The index is created.
SQL & gt; ALTER table a Add (constraint primary key (a1) using index pk_a);
Modified table.
Another way:
SQL & gt; CONN u1/u1@db1
Connected.
SQL & gt; create table a (a1, b1 varchar2 number (2), the date c1)
2.
Table created.
SQL & gt;
SQL & gt; ALTER table a Add (constraint primary key (a1) using index tablespace t1 pk_a)
2.
Modified table.
Which of the two approach is better? or are they the same?
Thank you
Cedric
Oracle will attempt to create the index to apply the constraint. Of course, it is certainly possible that the creation of the index will fail, but you would be just to move the point of failure of the CREATE INDEX statement to the ALTER TABLE statement, assuming that everything else is equal (that is, you create the index in the same tablespace, quotas and tablespace sizes are the same, permissions are not changed, etc.)
It may be preferable in some contexts to create a non-unique index before the creation of the constraint and instruct Oracle to use the non-unique index to apply the constraint. If you decide in the future to make the primary key constraint can be delayed, for example, have a non-unique index allows you to make this change without having to (implicitly), drop and re-create the index. A separate CREATE INDEX statement also influences when you go to remove a constraint / index. If the index was created before the constraint, you can remove the constraint without affecting the index. If the index was created after the constraint, deleting the constraint implicitly removes the index. Normally, particularly with OLTP applications, this doesn't buy you much. Sometimes, however, there are ETL process benefiting from such things.
Justin
-
Hi all
I created a test table which has 4 columns:
SR_NO, FNAME, LNAME, and GRADES.
The rank column has the same value repeat several times.
Then I intend to create a primary key on 3 columns: FNAME, LNAME, and GRADES.
alter table test_tab add the key primary constraint mv_testy_pk (FNAME, lname, rank);
and oracle allows me but I need to know that columns of rank has already repeated values in it, so what happens to the PK here.
BR
SphinxRead will have get the notion of primary key.
When you create a primary key knowledge composite primary key is composed of multiple columns, then it will check whether or not the combination of the data in the three columns are unique. for example:
lname: 1 Fname: abc grade: A
lname: Fname 2: def grade: AHere, although repeats in the shade, but the combination of three columns are unique... isn't it?
This is why oracle allows you to create the primary key.
-
Hello everyone.
Is there a way to create the primary key by order of decreasing its index?
I have a sql for MSSQL that looks like:
ALTER TABLE table_name ADD CONSTRAINT pk_name
KEY elementary SCHOOL (Column1 Column2 Column3 DESC, DESC, DESC)
How can I make in Oracle?
I tried this:
ALTER TABLE table_name
ADD CONSTRAINT PRIMARY KEY pk_name
*(*
Column1 DESC
*, Column2 DESC *.
*, Column3 DESC *.
*)*
ENABLE;
but I got this error:
Error report:
SQL error: ORA-00907: lack the right parenthesis
* 00907. 00000 - "lack the right parenthesis."
* Question: *.
* Action. *A reverse key index is distinguished by an index of desc.
I don't think that you can create a descending index to support a primary key because in Oracle a descending index is implemented as an index based on a function by using SYS_OP_DESCEND.
But you can create a unique index, for example
CREATE UNIQUE INDEX
ON ( The question is always why.
You can use an ascending index to make a descending sort. Maybe cannot MSSQL?
-
Primary key with PHPmysql database question
I know that the update of the primary key is a taboo subject, but I have a newsletter subscription form set up that works perfectly, but I can't understand how to create the primary key. I tried to use the subscriber email address (because its unique, but when trying to add a function to update, I realize that the e-mail address may have to be updated.)
My question is how do I get a primary key that works when I'm relying on a form variable to create the folder and did so no control over the assignment of one?
Is it possible to have one assigned automatically when a Subscriber clicks on the submit button?
This is why it is always a good idea to use surrogate keys. You can just have the database generates a unique id. In MySQL, I think that there is a column with the auto_increment attribute. If you then get this id after insert, php has functions for this (mysql_insert_id() I think).
-
Hi all
I have a table with the same data repeat 2 times. I mean that the lines are depating twice. so now, I create a primary key for the table. He throws me an error saying voilation key primary. I'll give you the clear script.
create table employee)
ID VARCHAR2 (4 BYTE) NOT NULL,
First name VARCHAR2 (10 BYTE),
VARCHAR2 (10 BYTE) last_name,
START_DATE DATE,
End_date DATE,
Number (8.2) of salary.
City VARCHAR2 (10 BYTE),
Description VARCHAR2 (15 BYTE)
)
insert into employee values ('01', 'Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Program');
insert into employee values ('02', "Alison", "Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver', 'Tester');
insert into employee values ('03', 'James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver', 'Tester');
insert into employee values ('04', 'Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, "Vancouver", "Manager");
insert into employee values ('05', 'Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver', 'Tester');
insert into employee values ('07', 'David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78, 'New York', 'Manager');
insert into employee values ('06', 'Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78, 'New York', 'Tester');
insert into employee values ('08', 'James', 'Cat', to_date('19960917','YYYYMMDD'), to_date('20020415','YYYYMMDD'), 1232.78, 'Vancouver', 'Tester')
insert into employee values ('07', 'David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78, 'New York', 'Manager');
insert into employee values ('06', 'Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78, 'New York', 'Tester');
The table is now with 10 columns
ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
---- ---------- ---------- --------- --------- ---------- ---------- ---------------
Jason Martin 25 July 96 01 25 July 06 1234.56 Toronto programmer
02 Alison Mathews 21 March 76 February 21, 86 6661.78 Vancouver Tester
03 James Smith December 12, 78 March 15, 90 6544.78 Vancouver Tester
04 Celia rice 24 October 82 21 April 99 2344.78 Vancouver Manager
Robert Black 05 January 15, 84 8 August 98 2334.78 Vancouver Tester
Linda Green 06 July 30, 87 January 4, 96 4322.78 tester of New York
Manager of New York 07 David Larry 31 December 90 February 12, 98 7897.78
08 James Cat 17-AUG-96 April 15 02 1232.78 ester of Vancouver
Create a primary key for the table
"Employee to ALTER TABLE PRIMARY KEY (ID, First_Name, Last_Name, start_date, end_date,
Salary, city, Description); »
I get error voilation primary key
IS IT POSSIBLE TO CREATE THE KEY PRIMARY ON THE TABLE WITH ON THE DELETION OF THE DATA?
Is IT POSSIBLE CREATING PRIMARY KEY USING 'GROUP BY' FUNCTION or OTHER FUNCTIONS?
Published by: user11872870 on September 23, 2010 17:41Primary key columns cannot contain NULL values. If you tried to create a primary key constraint, you will get an error like this:
ERROR at line 1: ORA-01449: column contains NULL values: cannot alter to NOT NULL
However, you can add a unique constraint by doing something like the following:
ALTER TABLE test ADD CONSTRAINT test_unq UNIQUE (column1, column2);
I still wonder why you take the approach you take. I have a vague feeling that're missing us the key pieces of information to recommend the correct solution.
-
By specifying the Composite primary key (columns 4 and 5)
Hi all
I am new to Oracle Apex,
I have a few paintings with a composite primary key (4 or 5 columns)... When I try to create a primary key constraint, it gives me only 3 columns!
Any help please in how can I solve this problem?
Thanks in advance
You are probably using the workshop for this sql Object Explorer
which seems to be limited to 4 columns on APEX 4.2.3
best thing to do is to create manually using the sql commands in sql workshop, here's an example:
{code}
CREATE UNIQUE INDEX myui ON JC_ACCOUNT
(TITLE_ID, FAMILY_NAME GIVEN_NAME, GENDER_ID, TELEPHONE_NUMBER)
/
{code}
I hope this helps you
KR
Martin
-
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
-
Hi all
I'm confused. If I create a primary key of table constraints, it willl create a unique index by default. If I create a foreign key, it also creates an index? of any kind?
Thank you very much
KinzLaughing out loud. foreign key does not have a unique index on the table.
Maybe you are looking for
-
Closure of a SELECTION of tabs at once. Is this possible?
Hi, I'm an average user of tabs. Let's say I opened 25 tabs in a window/session. I want to select 5 tabs to close, at one time, but without using the tabs groups/panorama that I am too clumsy use this feature. :-) I mean it takes more time to create
-
Satellite L755D - data partition D drive is full
I have a problem with the data drive on my Toshiba Satellite L755D. He easily gets full. Right now:(Translated from Danish) 40,18 GB datafiles SecuritycopyPhoto 106,26 GB systemAnother 15,08 GB files71,52 GB of free space I just deleted one of the se
-
Help please. I searched for a few days to solve this error that appears at startup upward. After the above, it says "the application requested execution to terminate in an unusual way. For more information, contact the application support team. The
-
Get errors when you try to activate Windows 2008 Standard Server
I upgraded my server from Windows 2000 to Windows 2008. When I try to activate Windows, I have the error first: Activation error: Code 0x8007232bDNS name does not exist So find kbase ID of Article: 929826 http://support.Microsoft.com/kb/929826 Trie
-
laptop Pavilion: network connection
On the list of available networks, I have one with a Red Cross, how do I get rid of him? Thank you