Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 primary key

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?
Go to Top of Page

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
Go to Top of Page

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
Go to Top of Page

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"
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-08 : 03:10:29
Tnx for the response.
I am studying index ...
Go to Top of Page

jafrywilson
Constraint Violating Yak Guru

379 Posts

Posted - 2010-09-08 : 03:17:01
1 wil 123
2 wil 222
NULL NULL NULL

this also allows duplicates in login_name column
Go to Top of Page

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..
Go to Top of Page

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..
Go to Top of Page

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 Shaw
SQL Server MVP
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-08 : 04:18:31
I wonder how long time it would take to backup a table with 1 quintillion customers?
http://www.jimloy.com/math/billion.htm



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -