Author |
Topic |
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 02:33:15
|
Hi.. Can i set two primary key ? ... I know i can't ..Is there any possibility in MS SQL 2005 server.. |
|
Kristen
Test
22859 Posts |
Posted - 2010-09-08 : 02:47:51
|
Two columns to make a single primary key? Yes.Two separate primary keys? No. But you can make additional indexes.What is the scenario you have? |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 02:51:58
|
I need to set primary key for login_name and id for the table |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 02:55:33
|
ADD CONSTRAINT pk_ID PRIMARY KEY (Id,Login_Name)..I used this to make primary key constraint ..But i can't get expected result..the column id does no allow duplicates but the column login_name allows duplicates..This is my problem |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2010-09-08 : 03:03:09
|
CREATE UNIQUE INDEX IX_ID ON Table1 (ID) INCLUDE (LOGIN_NAME) N 56°04'39.26"E 12°55'05.63" |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 03:10:29
|
Tnx for the response.I am studying index ... |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 03:17:01
|
1 wil 1232 wil 222NULL NULL NULLthis also allows duplicates in login_name column |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 03:30:37
|
create table us_log (id numeric(18,0) identity (1,1),login_name varchar(50)primary key,password varchar(50))CREATE UNIQUE INDEX IX_ID ON us_log(ID) INCLUDE (login_NAME)the above error occurred.. |
 |
|
jafrywilson
Constraint Violating Yak Guru
379 Posts |
Posted - 2010-09-08 : 04:00:49
|
setting primary key to a column and indexing to other is nice idea..sql generates new row every time ..If any row deleted can replace it for the new entry.. |
 |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-09-08 : 04:06:49
|
ALTER TABLE us_log ADD CONSTRAINT pk_Login PRIMARY KEY (ID)CREATE UNIQUE INDEX idx_Log_LoginName ON us_log (Login_Name)Why a numeric(18) for the ID? Are you really expecting that many rows?Max value that numeric(18) can store is 999 999 999 999 999 999. You could probably store a row for every atom in the galaxy and not hit that limit.--Gail ShawSQL Server MVP |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|