Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 3rd, 2005, 10:59 AM
Friend of Wrox
 
Join Date: Mar 2005
Posts: 264
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to addd one to one reletionship between 2 tabl

Hi guys i wonder if i can add one to one reletionship between 2 tables in sql server 2000 just like access 2000. I be happy if some one teach me how. IN the links below is the pics of my tables.I want to add one to one reletionship between players table and teams.Thanks

http://i5.photobucket.com/albums/y18...letionship.jpg

http://i5.photobucket.com/albums/y18...letionshp2.jpg
 
Old June 3rd, 2005, 11:39 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

Normally One-to-One relationships are not implemented as primary foreign key relationships alone.

You can implement it by having the same primary keys in both the tables

Regards
Ganesh
 
Old June 3rd, 2005, 11:42 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 449
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to r_ganesh76
Default

this is an example

Code:
CREATE TABLE [dbo].[Name] (
    [ID] [int] NOT NULL ,
    [Name] [char] (10)
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Age] (
    [ID] [int] NOT NULL ,
    [Age] [tinyint] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Name] ADD 
    CONSTRAINT [PK_Name] PRIMARY KEY  CLUSTERED 
    (
        [ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Age] ADD 
    CONSTRAINT [PK_Age] PRIMARY KEY  CLUSTERED 
    (
        [ID]
    )  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Age] ADD 
    CONSTRAINT [FK_Age_Name] FOREIGN KEY 
    (
        [ID]
    ) REFERENCES [dbo].[Name] (
        [ID]
    )
GO
Regards
Ganesh
 
Old June 5th, 2005, 07:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

But what you show isn't, and shouldn't be a one-to-one relationship.
If you are trying to make sure that a player is only in one team at a time then you can set a unique constraint on the player column in the team table.

--

Joe (Microsoft MVP - XML)





Similar Threads
Thread Thread Starter Forum Replies Last Post
auto update from 1 table to column in another tabl headwaters Access 1 December 1st, 2008 08:39 AM
Extreme performance problems with a repeating tabl gicio Infopath 0 November 18th, 2007 06:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.