Click here to Skip to main content
14,769,975 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to insert same value in auto generated column in sql server 2008

my table script is:

CREATE TABLE [dbo].[rr](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [name] [varchar](50) NULL,
    [add] [varchar](50) NULL

i want my table value like that

id      name    address

1	aa      noida
2	ss	delhi
2	dd      punjab
3	ee	okhla
Herman<T>.Instance 28-Jun-12 3:03am
why not use an update on that field Add with value from Name ?

Your question has lack of enough information to exactly understand your problem.

Bad idea.

The whole idea of a autogenerated column is that it holds unique values, not unique-except-when-I-feel-like-it values.
The whole purpose of an "ID" field is to uniquely identify a row, so that it can be handled correctly. With your scheme, an attempt to delete the second row could well delete the third as well - which is probably not what you want.

Leave IDs alone, make them unique and reconsider whatever you are doing that you think needs duplicate row ids.

What are you trying to achieve that you think this would be a good idea?

[edit]Minor typos - OriginalGriff[/edit]
YOu need to create the table without the column being specified as an identity, then insert the values you want, and then change teh column to be an identity, with the seed starting not at 1, but at 5 (in your example)
srishti_ 28-Jun-12 3:29am
i need to have a column identity i can't remove that. and want to insert same value in that column
You can use
SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }

statement to insert a value into identity column.

Detailed information is available at[^]
Hi ,
You can't do that as long you set IDENTITY on, Solution for this remove the IDENTITY and make your own function which make IDENTITY and be careful
if your column is PK you will not be allowed to duplicate data because PK have to be unique .
Best Regards
srishti_ 28-Jun-12 3:25am
its possible through identity column but how i don't know

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