473,387 Members | 1,515 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how can i make one column as primary key?

Hi All,
Here i have one table.what i need to do this is make one column as primary key.
How can i achieve that?
Thanking you,
Regards,
Suma
Sep 12 '07 #1
5 9058
amitpatel66
2,367 Expert 2GB
Hi All,
Here i have one table.what i need to do this is make one column as primary key.
How can i achieve that?
Thanking you,
Regards,
Suma
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE <table_name> ADD PRIMARY KEY (<column_name>)
Sep 12 '07 #2
pbmods
5,821 Expert 4TB
Heya, Amit.

Please use CODE tags when posting source code:

[CODE=MySQL]
MySQL code goes here.
[/CODE]
Sep 12 '07 #3
Would this code convert an existing column or add a new key column? I've been looking to convert a text column to a (unique) primary key without creating the table or column again.
edited:
I think this works in not only making it key, but a unique key:
Expand|Select|Wrap|Line Numbers
  1. ALTER TABLE counter ADD CONSTRAINT NEW_UNIQUE UNIQUE (IP(17));
Dec 27 '07 #4
pbmods
5,821 Expert 4TB
Heya, Saadshakil. Welcome to TSDN!

ADD PRIMARY KEY creates a new key, not a new column. In fact, the column must exist before you can index it.
Dec 27 '07 #5
Expand|Select|Wrap|Line Numbers
  1. alter table table_name add primary key(column_name)
Jan 24 '14 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ken1 | last post by:
I am going to drop a primary key from one column and create a new column to be used as primary key in an existing database. The old column was a date column which someone earlier though was a good...
1
by: Lannsjo | last post by:
I need to change my primary key column type from smallint to int. I have tried: ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT; But get an error message certainly since my...
1
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...
4
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...
3
by: mal_k100 | last post by:
Hi All, 1. Created table in SQL Server 2K with Primary key as int Identity 2. Link to table in MS Access 2K 3. Using form in MSAccess to update the linked table I want SQL server to...
6
by: Alpha | last post by:
I retrieve a table with only 2 columns. One is a auto-generated primary key column and the 2nd is a string. When I add a new row to the dataset to be updated back to the database. What should I...
11
by: Martin | last post by:
Hi, I understand you must first remove the constraint. The following bit does not work (where t is a DataTable). It gives a 'reference not set to an object' error ...
3
by: travlintom | last post by:
Hi all. I have a datagrid that has several columns including the Primary Key as the first column. When I add records to the grid the Primary Key column show "Null". This would not be a...
9
by: Steve | last post by:
How I can remove an AutoGenerated column? I wnat to inlcude the primary key in the resultset for creating some custom LinkButtons, but I don't want it (the PK) displayed in the DataGrid. I tried...
3
by: Shestine | last post by:
I am trying to add a column to a current table, with data in it. I am only learning, and i have no idea how to change this to make it work. Here is the script I have right now it, but what it does is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.