473,503 Members | 1,772 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

making a column the primary key post facto

Hi all,

I'm pretty new to MySQL, but have some Access background. I've created
a table for which I intended the email column to be the primary key,
but didn't specify it at creation. Now, I'm trying to figure out how
to specify it post facto.

Thanks,

blanch
Jul 20 '05 #1
1 1527
blanch wrote:
Hi all,

I'm pretty new to MySQL, but have some Access background. I've created
a table for which I intended the email column to be the primary key,
but didn't specify it at creation. Now, I'm trying to figure out how
to specify it post facto.


alter table add primary key (email_column);

http://dev.mysql.com/doc/mysql/en/ALTER_TABLE.html

But I have to point out that using email as a primary key isn't usually
an appropriate choice.

Is a given user's email address never going to change? If it can
change, how do other tables that reference this one make sure they
reference the correct record? You can enforce this behavior
automatically by declaring foreign keys with the ON UPDATE CASCADE
clause, but you have to remember to do that. And note that referential
integrity only works with InnoDB tables. See
http://dev.mysql.com/doc/mysql/en/In...nstraints.html

Sorry to make trouble! :-) I just want you to avoid difficulty later on.

It'd be better for data management to assign another column to be the
primary key. This column should have no significance other than its use
to uniquely identify the record. Therefore it has no reason to change
its value. It is customary to use an integer column for this purpose.

Regards,
Bill K.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
55927
by: js | last post by:
I am trying to create a primary key constraint on a view in the following statement. However, I got an error ORA-00907: missing right parenthesis. If the CONSTRAINT clause is removed, then the...
1
1247
by: blanch | last post by:
Hi all, I'm pretty new to MySQL, but have some Access background. I've created a table for which I intended the email column to be the primary key, but didn't specify it at creation. Now, I'm...
17
49791
by: Philip Yale | last post by:
I'm probably going to get shot down with thousands of reasons for this, but I've never really heard or read a convincing explanation, so here goes ... Clustered indexes are more efficient at...
4
25069
by: Peter Scott | last post by:
I created a table that has a column in that needs to contain a full Unix file path. Since 2048 was too long for a VARCHAR, I made it TEXT. I since populated the table. Now I want to make the...
2
1659
by: mel_palmeruk | last post by:
Hi I am having trouble with ms-access and trying to determind whether or not a row already exisitng in a particular table. I have 3 tables namly Projects, ProjectsAttencedByContact,...
0
974
by: Beryl Small | last post by:
Have a datalist bound to a dataset. When I run the following code it deletes the selected record from the screen but not from the underlying table. The dataset is made up of three joined tables,...
2
949
by: Kenny M. | last post by:
hi I have a WebForm1 with a button to navigate using Response.Redirect ("myPage2",true) and I have notice that the Webform1 makes a complete PostBack before leave, and that is making my app more...
10
27811
by: Bernie Yaeger | last post by:
I have a need to add a primary key to a dataset/datatable. How can this be done using a standard oledb data provider? Tx for any help.
0
2096
by: archana | last post by:
Hi all, I want to make one column of listview as multiline. My problem is my text contains multiple line. When i display that text in listview newline characters are not getting displayed...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7323
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.