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 Creating tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Creating tables" Watch "Creating tables" New topic
Author

Creating tables

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9353
    
    2

Guys,

When I'm creating tables, it I say just PRIMARY KEY is it enough for it to be NOT NULL and UNIQUE? Please let me know!


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30400
    
150

Those are the criteria for a primary key. You still need to identify it is a primary key.

Since this is about tables and not specific to Oracle, I'm moving it to our JDBC forum.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
A primary key is a lot more than just a non-null, unique field. The primary key is the field (or group of fields) which serve to uniquely identify a row. By declaring a primary key you are giving the database lots of information about how the table is structured and which columns depend on which others.

Primary key fields are almost always indexed, and defining a primary key is vital if you want to use foreign keys in other tables which reference this one, or features such as "REPLACE INTO" (which updates an existing matching row or inserts a new one if there is no existing row with the same key.)

The bottom line is that I can't think of a situation in which you should not define a primary key.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Creating tables