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 > all 3 fields as one primary key...

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-09-09, 13:21
qmqmqm qmqmqm is offline
Registered User
 
Join Date: Feb 2009
Posts: 5
all 3 fields as one primary key...

Hi

I need to create a table that records user's privileges of different files:

This works fine:
CREATE TABLE myTable
(
user_id INT NOT NULL,
file_id INT NOT NULL,
privilege_name TINYTEXT NOT NULL,
PRIMARY KEY (user_id, file_id, privilege_name)
)

However since privilege names could be read and write, and if the user has both read and write privileges, then we need 2 records. So I attempted to use all 3 fields as one primary key as follows:

CREATE TABLE myTable
(
user_id INT NOT NULL,
file_id INT NOT NULL,
privilege_name TINYTEXT NOT NULL,
PRIMARY KEY (user_id, file_id, privilege_name)
)

However now phpmyadmin gives me an error:
#1170 - BLOB/TEXT column 'privilege_name' used in key specification without a key length

Does anyone know how to solve this problem?

Thanks,

Tom
Reply With Quote
  #2 (permalink)  
Old 03-09-09, 14:00
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
Use VARCHAR instead of TINYTEXT.
Reply With Quote
  #3 (permalink)  
Old 03-09-09, 14:12
qmqmqm qmqmqm is offline
Registered User
 
Join Date: Feb 2009
Posts: 5
Quote:
Originally Posted by shammat
Use VARCHAR instead of TINYTEXT.
Hi Shammat

I used

privilege_name VARCHAR(15) NOT NULL,

and it worked. But could you please explain why TINYINT would not work?

Thank you very much.

Tom
Reply With Quote
  #4 (permalink)  
Old 03-10-09, 10:19
guelphdad guelphdad is offline
Registered User
 
Join Date: Mar 2004
Posts: 440
not tinyint but tinytext and it didn't work because when you include a column that is text/blob type you must specify the number of characters in that column that are part of the index.
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