Solved

multi primary key

Posted on 2014-02-08
4
300 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 76

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to recover a database from a user managed backup

805 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