Solved

multi primary key

Posted on 2014-02-08
4
304 Views
Last Modified: 2014-02-09
hi
i have a table "trans"
year  number
month  number
tran_no  number

trans_no should not be reapet within same year
but it could be for different year
0
Comment
Question by:NiceMan331
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
Leon Kammer earned 250 total points
ID: 39845031
To redefine your primary key to include more than one column, so the combination of values is unique for year and trans_no:

ALTER TABLE trans
DROP CONSTRAINT pk_trans;

ALTER TABLE trans
ADD CONSTRAINT pk_trans PRIMARY KEY (tran_no, year);

Just make sure there are no null values in the 2 columns, else thew constraint will fail to be created.

Cheers

Leon
0
 

Author Comment

by:NiceMan331
ID: 39845177
i found a constraint in the table
but i didn't find the related field
how to check it ?
0
 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 39845957
Did you not create the schema?

>>how to check it ?

What are you asking?

Are you asking what how that constraint is defined?

You 'could' query user_cons_columns to see the columns involved in the constraint but I would just generate the DDL:

select dbms_metadata.get_ddl('CONSTRAINT','CONS_NAME') from dual;

Just replace CONS_NAME with your constraint name.
0
 

Author Comment

by:NiceMan331
ID: 39846523
CORRECT
the constraint already defined 2 fields as PK
thanx to both of you
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This post first appeared at Oracleinaction  (http://oracleinaction.com/undo-and-redo-in-oracle/)by Anju Garg (Myself). I  will demonstrate that undo for DML’s is stored both in undo tablespace and online redo logs. Then, we will analyze the reaso…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.
Suggested Courses

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question