Should I create primary keys or foreign first?
I'm new to sql and a student please bear with me.I create a script so that when I run a sequence of tables are created. I created all of my fine tables but now I want to add the primary and foreign keys. I tried to do all this at once before but had problems, my idea was to use alter table instructions and add the constraints of key primary and foreign in this way.
The thing I want to know is what to build first? Should I do any foreign keys and primary keys or visa versa? Or can I do them sequentially and connect relationships between the tables that I will. Thanks in advance!
Hello
One thing to remember as a student is to apply logic to the task at hand. In this case, to create a foreign key, it must refer to a primary key in its definition as well so the KP must exist first. What I tend to do is to break down as statements in separate files or sections separate scripts and execute it in a logical order. IE Tables first, and then of PK and UK followed by the FK etc.. I also prefer to create offline rather than constraints in create table statements.
Hope this helps
André
Tags: Database
Similar Questions
-
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
-
Trigger - use one to create primary key values
I'm stuck on a simple use to do a TRIGGER that fires when you add new rows to a table and want to Developer SQL to add the primary key value.
I seem to be able to relax, but it is not inserted the primary key but giving a SQL error: ORA-00947: not enough values.
Here's what I have.
CREATE TABLE HF_fishers
(
contact_id INT NOT NULL
, name VARCHAR (25)
, last_name VARCHAR (35)
PRIMARY KEY (contact_id)
);
CREATE SEQUENCES HF_fishers_seq.
Then I ran the following trigger:
CREATE
HF_fishers_seq_trigger RELAXATION
BEFORE INSERTING
ON HF_fishers
FOR EACH LINE
BEGIN
IF (: new.contact_id IS NULL)
THEN
: NEW.contact_id: = NVL (: NEW.contact_id)
HF_fishers_seq. NEXTVAL
);
END IF;
END HF_fishers_seq_trigger;
=============
Then I executed the following SQL statement that gives the error.
INSERT INTO HF_fishers VALUES('Jacob','Muller');
But if I do everything is good except that it defeats the purpose of relaxation.
INSERT INTO HF_fishers VALUES(1,'Jacob','Muller');
MySQL has a nice 'AUTO_INCREMENT' command, but from what I understand in Oracle, I need to set up a trigger to automatically increment a column/cell, which in this case I use for the PRIMARY KEY.
3003916 wrote:
OK Jaramillo, I tried as you wrote, but what would be an INSERT statement correct?
-After the code trigger of Jaramillo
INSERT INTO HF_fishers (first_name, last_name) values ("Jesse", "Owens"); -I have the trigger but he made the mistake of duplicate key.
INSERT INTO HF_fishers values (hf_fishers_seq.nextval, 'Jesse', "Owens"); -No trigger but get key duplicated,.
INSERT INTO HF_fishers VALUES(:NEW_contact_id,'Jesse','Ownes'); -works without the trigger but the "get links" dialog box appears. So not much 'automatic' on this issue,.
My mistake. Here is the modified version of the trigger. I removed the CONDITIONAL clause and comes to be a part of the body of the trigger.
So, I created the table, the sequence, the relaxation and ran the first two insert statements and it worked fine. The third one you have invites SQL + or any tool you use to enter a value if she sees the ":" colon as a variable binding. Colon only works in a trigger without asking for confirmation.
Here is the code and my exit I ran home
DROP TABLE hf_fishers CASCADE CONSTRAINTS PURGE; DROP SEQUENCE hf_fishers_seq; CREATE TABLE hf_fishers ( contact_id INTEGER NOT NULL ,first_name VARCHAR(25) ,last_name VARCHAR(35) ,PRIMARY KEY (contact_id) ); CREATE SEQUENCE hf_fishers_seq; CREATE OR REPLACE TRIGGER hf_fishers_seq_trigger BEFORE INSERT ON hf_fishers FOR EACH ROW BEGIN IF(:NEW.contact_id IS NULL) THEN :NEW.contact_id := hf_fishers_seq.NEXTVAL; END IF; END hf_fishers_seq_trigger; INSERT INTO hf_fishers(first_name, last_name) VALUES ('Jesse', 'Owens'); -- Works with the trigger INSERT INTO hf_fishers VALUES (hf_fishers_seq.nextval, 'Jesse', 'Owens'); --Works without using the trigger body code. SELECT * FROM hf_fishers; COMMIT;
The output
Deleted table.
Elapsed time: 00:00:00.05
Sequence has fallen.
Elapsed time: 00:00:00.02
Table created.
Elapsed time: 00:00:00.03
Order of creation.
Elapsed time: 00:00:00.02
Trigger created.
Elapsed time: 00:00:01.05
1 line of creation.
Elapsed time: 00:00:00.04
1 line of creation.
Elapsed time: 00:00:00.01
CONTACT_ID FIRST NAME LAST NAME
---------- ------------------------- -----------------------------------
1 Jesse Owens
2 Jesse Owens
2 selected lines.
Elapsed time: 00:00:00.04
Validation complete.
Elapsed time: 00:00:00.01
-
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.
-
Create primary key also Select
In Oracle, how we specify a primary key in a creation like the select statement? I ran a simple statement, but received the error ORA-00933. What I have to do two steps with created first table and alter the table to add the key?
Thank you
CREATE TABLE Test as
SELECT
*
SOURCE one
WHERE a.sys = 100
PK1 CONSTRAINT PRIMARY KEY (account ID)SQL> create table t (a primary key) as select 1 from dual / Table created.
-
Primary key and foreign key between the different schemas
Hi all;
SCOTT user have a 'rank' of table-> it contains the primary key-> users tablespace
The U1 user have a 'emp' table-> it contains the foreign key-> test tablespace
U1 > select constraint_name, constraint_type, r_owner, owner, r_constraint_name of all_constraints where table_name = 'EMP ';
OWNER CONSTRAINT_NAME C R_OWNER R_CONSTRAINT_NAME
------------ ------------------------------ - -------------------------- ----------------------- -----------------------------------------------------
U1 EMP_EMPLEV_C12_FK R SCOTT GRADE_GRL_C1_PK
If I have connection U1, no possibility to find the name of the primary key without connection scott table?
Thank you
Hello
So, you want to know what picture of the SCOTT schema has the constraint that is named "GRADE_GRL_C1_PK." Isn't it?
If so,.
SELECT table_name
Of all_constraints
Owner WHERE = 'SCOTT '.
AND the argument constraint_name = 'GRADE_GRL_C1_PK. '
;
-
Creating primary key in online?
My database is oracle11g. My environment is 24 * 7.
I know that we can create indexes online. But here it is the primary key. I do below things... These tasks must not lock the table.
1 remove the primary key
2. recreate the primary key
3 remove the normal index
4 re-create the normal index.
Task 4 can be done online. I'm afraid the rest of the task.
1. no oracle locks the table while dropping the PK?
2. how to recreate the PK online?
3 oracle locks the table while removing the index?
Please let me know.Dear Shrinika,
If you read the ticket of Richard, you will find the answer to your question.
There is an improvement over 11 g and concurrent transactions are not owned by a lock of index.
Index lock will wait only active transaction that was created before the create index command.
Ogan
-
Creating primary key based on the Date
Hi all
I am trying to create a unique ID for each record, based on the date that the record is created. Example, if the folder is created today, I want to the key is 20101130XX where XX is a sequential list of numbers e.g. 01, 02, 03 etc... in the case where more than one person creates a record today.
If 3 people created record yesterday their unique ID would be
2010112900
2010112901
2010112902
and then comes the midnight and someone creates a new record, that it would be
2010113000
This is intended to give each record with a unique ID that will be used to reference the ticket.
We are already using the date format, but currently users have to manually enter the id and who can create errors such as 2011112900 when it should have been 2010112900 then instead of 2010 they put 2011
I'm not sure how to create a trigger to generate this type of unique identification number and would appreciate any help
Thanks in advance
WallyNever said it was perfect, but then again, it is a rather sticky issue... Reset sequence work would be scheduled to run @ some point... You entered in tables past 24/7? I would say that system could be locked for those 5 minutes sequence is updated, or the table is locked to allow no access while the process is...
To be honest, that is the question in the design of a key value that is dependent on outside data, as apposed to a surrogate key, which is generated System... Again, you could have at ONCE and have the surrogate for a key key REAL primary and date + sequence as a secondary key for the use of basic unit of carbon...
Thank you
Tony Miller
Webster, TXIf vegetable oil is made from vegetables, then what is baby oil?
-
Forgive my question. I am very new to Oracle.
How can I make sure that changes in the key primary supplier_id (concerning the supplier table) would also appear directly in the FOREIGN KEY (supplier_id) in the products table?
Is that not all the primary key and FOREIGN KEY on?
My paintings:
I created 2 tables and connect to apply in the data base referential integrity, as I learned.
CREATE TABLE - parent provider
(the numeric (10) of supplier_id not null,)
supplier_name varchar2 (50) not null,
Contact_Name varchar2 (50).
CONSTRAINT supplier_pk PRIMARY KEY (supplier_id)
);
CREATE TABLE - child products
(the numeric (10) of product_id not null,)
supplier_id numeric (10) not null,
CONSTRAINT fk_supplier
FOREIGN KEY (supplier_id)
REFERENCES beg (supplier_id)
);
I inserted the following text:
INSERT INTO provider
(supplier_id, supplier_name, contact_name)
VALUES
(5000, 'Apple', 'first name');
I expect that the supplier_id (5000) to the provider of the table also appears in the products table under key supplier_id having the same value which is 5000. But this does not happen.
How to get there?
Thanks in advance!
Hello
What is a foreign key in Oracle?
A foreign key is a way to ensure referential integrity in your Oracle database. A foreign key means that the values of a table must appear also in another table.
Ok!??
What is now the right way to implement referential integrity in your Oracle database that the values of a table must also be included in another table?
A foreign key referential integrity indeed enfore in ensuring that the value in the child table must have a corresponding parent key (otherwise you will encounter an error, as evidenced by "SomeoneElse"). However, it will never automatically insert a row in the other table.
If you are looking for a solution that automatically inserts a record in the other table, maybe you should go for triggers:
See:
-
Creation of primary keys, foreign keys and indexes
Hello
I created 60 new tables based on 60 existing tables.
The 60 current tables are named FY11_ACC1, FY11_ACC2, FY11_SALES1, FY11_SALES2..., but all of the 60 tables start with FY11. I created the same structured tables but with names like FY12_ACC1, FY12_ACC2, FY12_SALES1, FY12_SALES2 FY12...
I used the below SQL and generated SQL code.
Select 'create table ' | Replace (table_name, 11, 12).
' in select * from '. table_name | "where 1 = 0'.
from user_tables;
But this did not generate the PRIMARY KEYS, FOREIGN KEYS and INDEXES. How can I automatically or with similar like SQL above? _
Thanks for your time and your help.
How can I create primary keys, foreign keys and indexes for allssk1974 wrote:
Can you please provide me with more information or examples.Something like:
SET SERVEROUTPUT ON FORMAT WORD DECLARE h NUMBER; th NUMBER; ddl CLOB; BEGIN h := DBMS_METADATA.OPEN('TABLE_EXPORT'); DBMS_METADATA.SET_FILTER(h,'SCHEMA','SCOTT'); DBMS_METADATA.SET_FILTER(h,'NAME','DEPT'); DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''TABLE_DATA'''); DBMS_METADATA.SET_FILTER(h,'EXCLUDE_PATH_EXPR','=''STATISTICS'''); th := DBMS_METADATA.ADD_TRANSFORM(h,'DDL'); DBMS_METADATA.SET_TRANSFORM_PARAM(th,'PRETTY',false); DBMS_METADATA.SET_TRANSFORM_PARAM(th,'SQLTERMINATOR',true); LOOP ddl := DBMS_METADATA.FETCH_CLOB(h); EXIT WHEN DDL IS NULL; DBMS_OUTPUT.PUT_LINE (ddl); END LOOP; DBMS_METADATA.CLOSE(h); END; / CREATE TABLE "SCOTT"."DEPT" ("DEPTNO" NUMBER(2,0), "DNAME" VARCHAR2(14), "LOC" VARCHAR2(13), CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE) SEGMENT CREATION IMMEDIATE PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ; CREATE UNIQUE INDEX "SCOTT"."PK_DEPT" ON "SCOTT"."DEPT" ("DEPTNO") PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ; ALTER TABLE "SCOTT"."DEPT" ADD CONSTRAINT "PK_DEPT" PRIMARY KEY ("DEPTNO") USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "USERS" ENABLE; PL/SQL procedure successfully completed. SQL>
SY.
Published by: Solomon Yakobson January 5, 2012 16:22
-
Hi all
I need mapping composite primary key to foreign key.
Example:
first create LOCATION_MASTER table with composite primary key,
CREATE TABLE LOCATION_MASTER (LOC_CITYCODE VARCHAR2 (10))
LOC_CITY VARCHAR2 (30),
CONSTRAINT ANN_LOCMAS_PK PRIMARY KEY (LOC_CITYCODE, LOC_CITY)
);
Then create the route_master table. In the table route_master source_city, destination_city maps to loc_city
CREATE TABLE ROUTE_MASTER (ROUTE_ID NUMBER (3),)
SOURCE_CITY VARCHAR2 (30),
DESTINATION_CITY VARCHAR2 (30),
CONSTRAINT ANN_INPK PRIMARY KEY (ROUTE_ID).
CONSTRAINT ANN_INFK FOREIGN KEY (SOURCE_CITY, DESTINATION_CITY)
REFERENCES LOCATION_MASTER (LOC_CITY)
);
If I create like that, then I got error...
The samething is my need. So please fix the code that I have attached.
Please do what is necessary...
Thank you
AnnCONSTRAINT ANN_LOCMAS_PK PRIMARY KEY (LOC_CITYCODE, LOC_CITY)
CONSTRAINT ANN_INFK FOREIGN KEY (SOURCE_CITY, DESTINATION_CITY)
REFERENCES LOCATION_MASTER (LOC_CITY)It is not possible to refer to the part of the parent key. In your case, you must create a separate unique constraint on LOCATION_MASTER. LOC_CITY and then to establish referential constraints of ROUTE_MASTER. SOURCE_CITY and ROUTE_MASTER. DESTINATION_CITY individually i.e. two different referential constraints.
-
Problem with the primary key and indexes
Hi all
I'm looking a mess on one of our main tables.
One of the developers here added an index on 3 columns in the table, thinking that it would speed up (not noticing that it had not a PK).
Subsequently another developer has noticed there do not have a primary on key. So they added a touch of primry on the single column.
The problem is that now the index created on 3 columns is bein used as the primary key index. As when the primary key is created a new index was not created.
Is there anyway to get rid of this index/change it correct?
This table is related to many many other tables, so when we tried to remove the index we could not due to the primary key and foreign key violations with other tables.
Thanks in advanceOracle, as you found, is quite capable to use a column enformce multi index a single column primary key, as long as the pk column is the leader in the index. This should not cause performance issues for a search of PK and if the three indexed columns are often selected only may benefit from these types of queries.
The only way to change that now, would be to drop all CF, drop and add the PK constraint and then add all the FK constraints. A long time and potentially dangerous (if you miss to add back of the FKs) endeavour. Certainly not worth the risk in my opinion.
John
-
Primary keys in Tables Oracle EBS Standard
Hello! I was checking a few standard EBS tables and I just found it odd that there is no primary keys in the columns which (I think) should be the primary key:
an exaple:
AP_INVOICE_LINES_ALL DESC;
Column name ID PK Null value? Data type By default Histogram INVOICE_ID 1 N NUMBER (15) Yes LINE_NUMBER 2 N NUMBER Yes LINE_TYPE_LOOKUP_CODE 3 N VARCHAR2 (25 bytes) Yes REQUESTER_ID 4 THERE NUMBER (15) Yes DESCRIPTION 5 THERE VARCHAR2 (240 bytes) Yes LINE_SOURCE 6 THERE VARCHAR2 (30 bytes) Yes ORG_ID 7 THERE NUMBER (15) NULL VALUE Yes LINE_GROUP_NUMBER 8 THERE NUMBER Yes INVENTORY_ITEM_ID 9 THERE NUMBER Yes ITEM_DESCRIPTION 10 THERE VARCHAR2 (240 bytes) Yes SERIAL_NUMBER 11 THERE VARCHAR2 (35 bytes) Yes MANUFACTURER 12 THERE VARCHAR2 (30 bytes) Yes GL_CODE_COMBINATIONS DESC;
Column name ID PK Null value? Data type By default Histogram CODE_COMBINATION_ID 1 N NUMBER (15) Yes LAST_UPDATE_DATE 2 N DATE Yes LAST_UPDATED_BY 3 N NUMBER Yes CHART_OF_ACCOUNTS_ID 4 N NUMBER (15) Yes DETAIL_POSTING_ALLOWED_FLAG 5 N VARCHAR2 (1 byte) Yes DETAIL_BUDGETING_ALLOWED_FLAG 6 N VARCHAR2 (1 byte) Yes ACCOUNT_TYPE 7 N VARCHAR2 (1 byte) Yes ENABLED_FLAG 8 N VARCHAR2 (1 byte) Yes I checked 11i and R12 versions of our Tables to EBS, but both contain primary keys.
Is this normal or just tell set primary keys?
Please notify.
Thank you!
PS.* I'm trying to settle our scripts and he is still running a full table scan, because it doesn't have a primary key.
Hello
This is the standard installation done by oracle at time of installation of EBS in your organization therefore does not necessarily create a new primary key or an index
on the table.
The key primary is a combination of unique key constraint not null, and if you look at the script or the definition of the table, you will get the already
Ed configuration not null not forced and a unique index on some of the columns required by oracle.
-
manually assign primary key and copy to the detailed form
Hi experts,
Oracle Apex 4.2, 11g database, using windows 7.
I created a form and created automatic product no. (not only sequence) with logic and SQL. SQL query produced good wise exercise, and exercise begin from 01 July and ends 30 June each year. This means if the 07/01/2015 start it will create a new voucher No.
The main Table name is GL_PV and the columns are:
Number of PV_No
Date of PV_Date
Number of CC_code
number amount
Remarks varchar2 (100)
Created a process to submit before the calculations and validations.
The codes are
NVL SELECT (MAX (to_number (nvl(pv_no,0))) + 1, 1) AMENDMENTS
IN: P15_pv_no
OF GL_PV
WHERE pv_date
BETWEEN to_date (' 01-07-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))
+ case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = end of another 0, then 6-1), "dd-mm-yyyy")
AND to_date (30 - 06-' |) (extract (year from to_date (: P15_pv_date, "dd-mm-yyyy")))
(+ case when extracted (month of to_date (: P15_pv_date, "dd-mm-yyyy")) < = 6 then 0 otherwise 1 end), "dd-mm-yyyy")
and cc_code =: P15_cc_code;
and press the button when Conditions = Generate_Button
In the form of master I put the data and click on create button is working well and generating good can result.
Now that I've created a detail of my detail table is pv_detail and the columns are
pv_voucher_no
pv_date
account_code
Remarks
amount
I want to create the relationship of the master / detail form.
I tried:
- primary key and foreign key, but does not. column GL_PV table primary key (PV_NO, PV_DATE), PV_DETAIL (pv_voucher_no, pv_date) foreign key table columns: -.
- has created one for master and 2nd 2 form for details, good master shape generates but not detail of.
I want to assign pv_no, pv_date in both value table (master / detail), in other words copy value pv_no and pv_date of main table in detail table pv_voucher_no and pv_date.
Please advise how I can solve this problem.
Thank you forum oracle to solve my problems.
error report: ORA-01790: expression must have the same type of data, matching expression
Find the solution on this forum
Solution:
Attributes and the tabular form:
Change the default type = PL/SQL Expression on the function
Default = to_date(:P15_PV_DATE,'DD-MON-YYYY')
-
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.
Maybe you are looking for
-
How to connect to the Internet directly through my Office Firefox icon?
MSG appears telling me that it cannot connect to my ISP (PeoplePC) home page
-
My AutoFill is no longer present on the toolbar and I can not find where to change personal information such as the credit cards etc. I don't want to automatically fill in the password, but the credit cards etc. The old auto-fill button is gone and n
-
my freezer scandisk to 0% at the start of the computer. someone please tell me how to solve this problem, and for this reason, I can't use my computer for other things as well. It is now very slow and do not file load. as adobe flashplayer doesn't lo
-
How to install a driver for f4500? Error dot4_plugin.exe has stopped working
I had this printer HP Desk Jet F4500 connected to my computer laptop operating system windows 7 64 bit for months now, the printer has no drivers and I can't get them. I went on HP website and downloaded the base and the recommended full downloads a
-
How to include a document in email without being an attachment
e-mail message I want to send an e-mail message and then include an entire document after him. I don't want as an attachment. How can I accomplish this? Thank you T: