Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-Server
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 28-Jun-13 20:44pm
Comments
Shafeequl at 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 at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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)
 
)
  Permalink  
Comments
keyur_raval at 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 at 1-Jul-13 1:59am
   
No buddy.. that's not possible.. you can have only one identity column per table..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can Assign Primary key in this manner.
 

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)
)
  Permalink  

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

  Print Answers RSS
0 CPallini 385
1 BillWoodruff 344
2 George Jonsson 295
3 Sergey Alexandrovich Kryukov 293
4 OriginalGriff 222
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 29 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100