• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating tables

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34839
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic