Solved

multi primary key

Posted on 2014-02-08
4
301 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
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Configuring and using Oracle Database Gateway for ODBC Introduction First, a brief summary of what a Database Gateway is.  A Gateway is a set of driver agents and configurations that allow an Oracle database to communicate with other platforms…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

756 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