troubleshooting Question

Creating a primary key from two fields in the same table

Avatar of Scott Palmer
Scott PalmerFlag for United States of America asked on
DatabasesOracle DatabaseSQL
10 Comments1 Solution90 ViewsLast Modified:
I am using PL SQL with an Oracle database
I am trying to make a primary key from two fields in a table.

The table is  dhcs_contstat_hn2017_TEMP
The new primary key field is called "PrimaryKey".  But it is not set as a primary key yet
The fields I am using to make the field are "record_id" and "main_sgmnt_id_no".
The primary key needs to be inserted on the line that matches the "record_id" and "main_sgmnt_id_no".

I have the psuedo code below, .    

INSERT INTO dhcs_contstat_hn2017_TEMP c
(PrimaryKey)
SELECT concat(t.record_id, t.main_sgmnt_id_no)
FROM dhcs_contract_status_hn2017 t
WHERE c.main_sgmnt_id_no = t.main_sgmnt_id_no
;
How do I do this?

Thanks,
Scott
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros