954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

multi field combine key

Hi
I m thinking about combined key system. say i have mysql table having field
1. user_name
2. father_name
3. mother_name
4. Address

Now I can mark user_name field as key for unique value.
But I dont want that. I want that same user name is possible but same user name, father name and mother name combine is not possible. combined they must unique. mor easily

1. name01, father01,mother01
2. name01, father01,mother02
3. name01, father02,mother01
above data entry may be allow
But I want that
1. name01, father01,mother01
2. name01, father01,mother01
above data entry will not be allowed

arctushar
Junior Poster in Training
66 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

CREATE TABLE student(
name CHAR(100),
father CHAR(100),
mother CHAR(100),
address VARCHAR(255),
PRIMARY KEY (name,father,mother)
)

hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 
CREATE TABLE student( name CHAR(100), father CHAR(100), mother CHAR(100), address VARCHAR(255), PRIMARY KEY (name,father,mother) )


thanks it works for me. now how can edit primary key. another question field has been set unique wrongly. how can I ununique now.

arctushar
Junior Poster in Training
66 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Refer to the manual:
http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

Specifically, in the user comments at the bottom of the page, look for the comment
"Posted by Duane Hitz on March 31 2006 8:19am"

hielo
Veteran Poster
1,124 posts since Dec 2007
Reputation Points: 116
Solved Threads: 244
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: