Click here to Skip to main content
15,886,823 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir/Medam,
i have a little problem while i make table in database.
My table like this.

CREATE TABLE [Customer]
(
CustomerId int Identity(1,1) PRIMARY KEY,
CustomerNumber int Not Null Identity(1,1) UNIQUE

)
iS that possible to gives identity in 2 column of table like this.

Give me reply.....
Posted
Comments
Shafeequl 29-Jun-13 3:06am    
i think its not possible to have two same identity in same single table...
Actually What you need to do??
RedDk 29-Jun-13 14:14pm    
I see a code block that looks syntactically ok. When F5ing that block, does the interface you're using send back an error? If the answer to this question is "no", then ... it IS indeed possible.

Hello,

first you can have only one identity column per table, second i didn't get why you need two identity columns in your table?? As even if you get success to have two identity columns, you will get same sequence as a combination of these two (for eg. (1,1),(2,2,)....) which is useless i guess.. so what would be the benefit of that??

see if composite key works well according to your requirements... or tell us more that what you want to achieve so that we would be able to help you out.

CREATE TABLE [Customer]
(
CustomerId int Identity(1,1) ,
CustomerNumber int Not Null ,
PRIMARY KEY (CustomerId, CustomerNumber)
 
)
 
Share this answer
 
Comments
keyur_raval 1-Jul-13 1:53am    
I dont want primary key on column CustomerNumber.I want only gives identity(1,1) on CustomerNumber.and also give identity(1,1) on column CustomerId.
Is that possible or not?????????

Give me Reply for this problem....
Adarsh chauhan 1-Jul-13 1:59am    
No buddy.. that's not possible.. you can have only one identity column per table..
You can Assign Primary key in this manner.


C#
CREATE TABLE Persons
(
P_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255),
CONSTRAINT pk_PersonID PRIMARY KEY (P_Id,LastName)
)
 
Share this answer
 
You can not set two primary keys in one table but you can use composite key in your table or you can use unique key for not allow duplicate data.
If this one not solve your problem explain your question in brief with code.
 
Share this answer
 
Well...yes...but it won't do what you think it will.

You can't have two separate identity fields on the same row - they do not work well together, and if they did, they would always be the same number, so it would be ridiculous to have them both anyway.

What are you trying to achieve, that you think this is a good solution?
 
Share this answer
 

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