Jump to content

is a primary key needed here


jimfog

Recommended Posts

I have made a table which keeps the mails of the app. One column keeps the mail type.

This column is referenced by another table which in turn has 2 column types.

 

In this second table one of the column is VARCHR in which a description of the type of mail is used(support,general) and the second column is ENUM with the description of the first column corresponding to a number, such as 1 for support mail.

 

My question has to do with the second table mentioned above. Since the rows are fixed(none is added) I do not think a primary key is needed.

 

Is my assumption correct according to you?

Link to comment
Share on other sites

A primary key is needed for any table, although in some cases it is a composite of multiple columns or an artificially created index column. Every row of the primary key column must be unique and ideally the primary key should be an integer or other small data type.

Edited by davej
Link to comment
Share on other sites

A primary key is needed for any table, although in some cases it is a composite of multiple columns or an artificially created index column. Every row of the primary key column must be unique and ideally the primary key should be an integer or other small data type.

In the table I describe every row is uniquely identified by the ENUM number(either way).The first row for example has 1 and the second 2, and so on...

Given the above I cannot understand why a primary key is needed...

Link to comment
Share on other sites

Wondering if Primary key's are made for SQL clients, so they know how to work with rows. Example if i delete row at SQL it says.

DELETE FROM items WHERE id = '1'DELETE FROM items WHERE id = '5'DELETE FROM items WHERE id = '6'DELETE FROM items WHERE id = '8'
Link to comment
Share on other sites

 

Wondering if Primary key's are made for SQL clients, so they know how to work with rows. Example if i delete row at SQL it says.

DELETE FROM items WHERE id = '1'DELETE FROM items WHERE id = '5'DELETE FROM items WHERE id = '6'DELETE FROM items WHERE id = '8'

I do not understand what are you trying to say.

Link to comment
Share on other sites

All of your tables should be in 3rd Normal Form. Do you know what that means? Among other things it means having a primary key. Once a primary key is declared the database will enforce uniqueness constraints to assure that the primary key column(s) form a valid primary key.

 

http://en.wikipedia.org/wiki/Third_normal_form

Edited by davej
Link to comment
Share on other sites

In the table I describe every row is uniquely identified by the ENUM number(either way).The first row for example has 1 and the second 2, and so on...

Given the above I cannot understand why a primary key is needed...

I don't think you're asking the right question. The question should be is there a reason to not have a primary key. If you have a unique column, then why wouldn't you make that the primary key? Do you just not like taking advantage of primary keys?

Link to comment
Share on other sites

 

If you have a unique column, then why wouldn't you make that the primary key?

 

Yes, you are right, I have not thought of that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...