Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes Creating tables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Creating tables" Watch "Creating tables" New topic

Creating tables

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 10032


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
author & internet detective

Joined: May 26, 2003
Posts: 33106

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Frank Carver

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 ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
I agree. Here's the link:
subject: Creating tables
It's not a secret anymore!