user2001253
user2001253

Reputation:

Is it necessary to have separate column for primary key in table?

I have column having name id in my table. id is the primary key in table. I want to know that is it necessary to have separate column for id as it is primary key in my table.

Upvotes: 1

Views: 366

Answers (4)

Ranjit Singh
Ranjit Singh

Reputation: 3735

The PRIMARY KEY constraint uniquely identifies each record in a database table and if your table already contain that column then u don't need to add another column.

Upvotes: 0

Andrzej Gis
Andrzej Gis

Reputation: 14306

It's always better to keep things simple. If you already have a column that identifies the record it's just fine - don't add a new one.

There is also something called composite primary keys. You can use it if a combination of 2 or more columns always creates a unique sequence. Than you don't really need the 'Id' column. The truth though is some frameworks don't like this approach.

In your case the column you already have should be sufficient.

Upvotes: 1

Marlin Pierce
Marlin Pierce

Reputation: 10079

Any field or combination of fields can be a primary key if:

  1. The values in those fields are always non-null.
  2. The records with values in those fields are unique.
  3. Those fields are immutable. That is, you won't change the values of those fields after the record is created.

Upvotes: 1

Omar
Omar

Reputation: 463

Not necessary to have a separate column, you could have an existing column as primary key if it can identify each record uniquely..

Upvotes: 1

Related Questions