Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I define 2 rows as primarykeys?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I define 2 rows as primarykeys?<br><br>I am working on a project on moving an existing Access97 db to SQL Server 7.<br><br><br>I have now converted the databse and are working with it in SQL Server.<br><br>In the Access97 db sometimes a table has 2 primarykeys, but when I try to define primarykeys for the same 2 rows in SQL Server it only lets me have one primarykey- it removes the primarykey from the other row and then defines the second row as primarykey. I wonder how I could have both rows be primary keys.<br><br>I appreciate any help you can give me!<br><br>regards Mr. Jonas J
 
I already realised how easy it is. I just hold down ALT GR while selecting two rows :)
 
Just to make it clear: what Mr. Jonte wanted was to identify two rows as parts of a single primary key (aka a compound key), not two primary keys.&nbsp;&nbsp;By definition, you cannot have two different primary keys in one table. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
Well, let's get really sticky, and call them columns, not rows.&nbsp;&nbsp;Otherwise I have to set my monitor on its side. <p>Malcolm Wynden<br><a href=mailto:wynden@island.dot.net>wynden@island.dot.net</a><br><a href= > </a><br>
 
<FONT FACE=monospace>SET EMBARRASSMENT = 1</font><br><font color=red>Ding Ding Ding! </font> Of course I <i>intentionally</i> said &quot;rows&quot; just to see who was paying attention.<br><br>Actually, I was visualizing the Design Table screen while typing it, figuring that's what he would be using, and visually the columns are rows. <p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br>
 
I'm having the same problem but don't have access to the nice GUI as i'm working off a web server.

If someone could post an example of the sql needed to create a compound key i would be eternally grateful.

Lukas
sofnology@xtra.co.nz
 
CREATE TABLE [dbo].[compoundkey] (
[pk1] [int] NOT NULL ,
[pk2] [int] NOT NULL ,
[notpk] [varchar] (10) NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[compoundkey] WITH NOCHECK ADD
CONSTRAINT [PK_compoundkey] PRIMARY KEY CLUSTERED
(
[pk1],
[pk2]
) ON [PRIMARY]
GO
 
Whoops! I made a slight syntax error. A comma was out of place.

Create Table CustomerOrders (CustID Int, OrderID Int
Primary Key (CustID, OrderID)) Terry
------------------------------------
Experience is the hardest kind of teacher. It gives you the test first, and the lesson afterward.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top