Create two Tables (Table A & Table B) with the Primary Key on Both the tables.Ģ. Therefore, it will always have only one matching row between the Person-PassportDetails table based on the dbo.Person(Pk_Person_Id)-dbo.PassportDetails(Fk_Person_Id) relationship.ġ. One-to-One Relationship is implemented using dbo.Person(Pk_Person_Id) as the Primary key and dbo.PassportDetails(fk_person_id) as (Unique Key Constraint-Foreign Key). INSERT INTO dbo.PassportDetails VALUES ( 103, 'A4DEK33D', 3) INSERT INTO dbo.PassportDetails VALUES ( 102, 'VRDK5695', 2) GO INSERT INTO dbo.PassportDetails VALUES ( 101, 'C3031R33', 1) INSERT INTO dbo.Person VALUES ( 'Chetan', ' ') INSERT INTO dbo.Person VALUES ( 'Vishwanath', ' ') INSERT INTO dbo.Person VALUES ( 'Niraj', ' ') Let’s implement this in SQL Server.įk_Person_Id INT UNIQUE FOREIGN KEY REFERENCES dbo.Person(Pk_Person_Id) With One-to-One Relationship in SQL Server, for example, a person can have only one passport. This relationship can be created using Primary key-Unique foreign key constraints. One-to-One (1-1) relationship is defined as the relationship between two tables where both the tables should be associated with each other based on only one matching row. This tech-recipe covers only 1-1 and 1-M relationship. Many-Many Relationship (M-M Relationship)
One-Many Relationship (1-M Relationship)Ĭ. One-One Relationship (1-1 Relationship)ī. This relationship can be implemented by using (PK_Author_Id as Primary Key) and (Fk_Author_Id as Foreign Key). Book table (pk_book_id, title, ISBN) is associated with Author (pk_author_id, author_name, phone_no, fk_book_id). A link is created between two tables where the primary key of one table is associated with the foreign key of another table using database relationships.Ĭonsider the following example. In SQL server, these relationships are defined using Primary Key-Foreign Key constraints. Relationships are defined on the basis of matching key columns. Database designs are closely related to database relationships, the association between two columns in one or more tables.