473,394 Members | 1,811 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,394 software developers and data experts.

creating a new numbered column as primary key in a table

This is a fairly simple question, but what is the easiest way to:

create a new numbered column (where value is simply the row number) in
an existing table and setting it as a primary key?

Jul 23 '05 #1
1 1204
There is no such thing as a "row number" in SQL Server. The easiest way
to add an arbitrary, unique number to a table is to add an IDENTITY
column. You can then add a primary key constraint to that column if you
wish.

There is no point making IDENTITY the *only* key in a table though. You
should also declare a unique constraint on some other column(s) too. If
you have existing duplicates in the table then IDENTITY can help you
clean up the data by giving you a unique key to delete against.

--
David Portas
SQL Server MVP
--

Jul 23 '05 #2

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

Similar topics

9
by: Don Grover | last post by:
I have a HTML table created using ASP as a web page. ie. HEADING1 HEADING2 HEADING3 etc... data 1 data2 data3 etc and so on How can I toggle hide /...
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...
2
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,...
6
by: Ken | last post by:
I have a table I am trying to create with a unique Pk Table fields JobID---PK JobDate I would like to have the primary key be a combination of increment number starting with 001 and year and...
0
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,...
6
by: Christopher Lusardi | last post by:
How can I fix this? When I do the below I get the error message: "Cannot insert explict value for identity column in table 'Employees' when IDENTITY_INSERT is set to OFF." To get this message,...
1
by: Lawless | last post by:
With T-SQL if you write something like: amount = 1 and amount is not a defined column in the table you are using to draw data from, it will make a column named "amount" and fill it with the value 1 ...
6
by: Chandan Kr Sah | last post by:
How to drop primary key constraint from a column of table ? Actually I got so many example for this, but in that we require the primary key name also. But I dont have the primary key name.So if I...
1
by: Ching Li | last post by:
Hi Lets say I have a table MyUser (column: MyuserID, Username) Another table Product (column: ProductID, ProductName) Then I created a table MyUser_Audit (column: MyUserID, Username,...
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: 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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
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...

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.