Click here to Skip to main content
15,904,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with SQL-server2008.
For my table I need an auto-Increment(int) field.
But it should not be a Primary-key field.
How can I achieve this..Plz provide the steps..
Posted

There is no way to get it unless you have another Identity field and the required non identity field is derived from it. Why do you want to make it a non identity in the first place?
 
Share this answer
 
Comments
SHAJANCHERIAN 12-Apr-11 23:59pm    
My table fields are as follows.
//-----------------------------
item_id (This should be an int-AutoIncrement. How can I achive this)
Item_Name(primary-Key)
Item_Brand(primary-Key)
Item_ModelNo(primary-Key)
Pong D. Panda 13-Apr-11 0:17am    
What you can do is create an Identity column named item_id with autoincrement as your PK and the other 3 column can be declared as cluster index instead.
For example when creating the table with T-SQL use the IDENTITY keyword for the proper column. Something like:
SQL
CREATE TABLE MyTable (
   Col1 INT NOT NULL PRIMARY KEY,
   Col2 VARCHAR(100),
   Col3 BIGINT IDENTITY(1,1)
)

For more details, see: CREATE TABLE[^]

[Addition]
Just saw you other post and based on that I got the impression you're using a primary key with several other columns and this identity on alongside it. I would suggest to do it vice versa. Use this identity field as your primary key (both in the database and in the application) and have a unique key on the other columns.
 
Share this answer
 
v3
Comments
SHAJANCHERIAN 13-Apr-11 1:14am    
Thanks..
Wendelius 13-Apr-11 11:00am    
You're welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900