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 2000 Forums
 SQL Server Development (2000)
 Composite Key == Natural Key

Author  Topic 

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-11-06 : 13:47:16
If I have a Composite Key (lets say two fields that make a record unique) is that the "natural key" for the record?

Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>

MichaelP
Jedi Yak

2489 Posts

Posted - 2002-11-06 : 14:02:55
Here's a question that goes along with the original question.

I have Contacts, and Groups of contacts. A Contact can belong to multiple groups. Contact Group's Names are unique for each user.

I think that the following design will work well and perform well. I guess the question is should I put an arbitrary key (Identity) and a Unique constraint in the Contact Group table, or leave it like it is??

 

CREATE TABLE #Contact (
[ContactID] [int] IDENTITY (1, 1) NOT NULL , --PK
[UserID] [int] NOT NULL ,
[FirstName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[LastName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Phone] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Fax] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[Email] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)

CREATE TABLE #ContactGroupContacts(
[UserID] [int] NOT NULL ,
[GroupName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[ContactID] [int] NOT NULL
)

CREATE TABLE [dbo].[ContactGroup] (
[UserID] [int] NOT NULL ,
[GroupName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[SortOrder] [int] NOT NULL ,
[Cre_Date] [datetime] NOT NULL ,
[Cng_Date] [datetime] NOT NULL
)

CREATE UNIQUE CLUSTERED
INDEX [PK_ContactGroup] ON [dbo].[ContactGroup] ([UserID], [GroupName])



Michael

<Yoda>Use the Search page you must. Find the answer you will.</Yoda>
Go to Top of Page

Page47
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2002-11-06 : 14:05:12
A natural key can be made up of one or more naturally occuring columns that uniquely define a row in a table.

Jay White
{0}
Go to Top of Page
   

- Advertisement -