If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Is primary key really imp when theres no relation with other TBL

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-04, 08:22
chinni chinni is offline
Registered User
 
Join Date: Jan 2004
Posts: 12
Is primary key really imp when theres no relation with other TBL

Hello,
Does it make sense if i design a table with 2 columns with out defining any key?
username varchar(64) notnull and password varchar(64) notnull
This table does'nt have relation with any other table, shld we really have an id field???
lets say if i compare the username and password entered by the user against the values stored in the table by using the following prepared statements, will it have any disadvantages??

pstmt = connection.prepareStatement("select * from TBL_NAME where username='"+Uname.getText()+"' and password = '"+new MD5().getHash(Passwd.getText())+"';");
rset = pstmt.executeQuery();

As of now everything works fine, but i'd like to know if its a good design.

Thanks for your time
Reply With Quote
  #2 (permalink)  
Old 02-09-04, 08:29
reneeb reneeb is offline
Registered User
 
Join Date: Jan 2004
Location: Germany
Posts: 167
you need a key to keep the entries unique. If the key is missing you can use one username and one password several times...
__________________
board.perl-community.de - The German Perl-Community
Reply With Quote
  #3 (permalink)  
Old 02-09-04, 10:22
vanekl vanekl is offline
Registered User
 
Join Date: Nov 2003
Posts: 91
You should have a primary key defined so that (at the minimum)
you have a means of quickly SELECTing from your records.
A primary key automatically creates an index for you. This index
will become very important when your database gets large.

That said, there's no important reason why you need a separate
ID field. Your username field would make a good primary key field if you
want usernames to be unique. If usernames don't have to be unique,
then you could make a compound primary
key using both username and password.
Reply With Quote
  #4 (permalink)  
Old 02-09-04, 10:54
chinni chinni is offline
Registered User
 
Join Date: Jan 2004
Posts: 12
Thanks for your responses.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On