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)
 One - One relationships

Author  Topic 

konark
Yak Posting Veteran

60 Posts

Posted - 2010-01-28 : 13:55:49
Isearched many forums to get a demo of one-one relationships. But could not get a proper answer?

Can some one illustrate how to create a one-one relationship in SQL SERVER 2005.

Chandragupta Mourya

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-01-28 : 14:27:05
I'm not sure you can actually due a true 1:1 since that is the chicken and the egg scenario, but here is a 1 to 0 or 1:
CREATE TABLE Person 
(
ID INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
FirstName VARCHAR(20),
LastName VARCHAR(20)
)

CREATE TABLE PersonDetail
(
ID INT NOT NULL PRIMARY KEY,
PersonDescription VARCHAR(MAX)
)

ALTER TABLE PersonDetail
ADD CONSTRAINT FK_PersonDetail_ID_Person_ID FOREIGN KEY (ID) REFERENCES Person (ID)
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2010-01-28 : 14:41:27
A true one-to-one relationship would just be a single table, since all columns in a row are (or should be) related to the same key.





CODO ERGO SUM
Go to Top of Page
   

- Advertisement -