File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes SQL problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL problem" Watch "SQL problem" New topic
Author

SQL problem

Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 131

Hi all!,
I've created a table with 2 attributes as a primary key.
another table has a foreign key references 1 attribute of previous table.

Is it incorrect? (MySQL is ok with it)


Are you better than me? Then please show me my mistakes..
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 9990
    
    7

This would be more suitable on the JDBC forum. Moving...


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3434
    
  47

I'd say it is incorrect.

Primary key ensures uniqueness. But individual columns of a primary key are (in general) not unique. Foreign constraints are required by SQL standard to refer to a unique key. I'm surprised that MySQL even allows his situation.
Supun Lakshan Dissanayake
Ranch Hand

Joined: Oct 26, 2012
Posts: 131

Martin Vajsar wrote:I'd say it is incorrect.


Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: SQL problem
 
Similar Threads
problem while inserting values
modelling an association with entity beans
Dont know how to map if there is no primary key???
regarding surrogate key and primary key
relation without ID attribute