![]() ![]() ![]() This kind of Relationship, allows a Car to have multiple Engineers. This type of relationship can be created using Primary key-Foreign key relationship. This is where a row from one table can have multiple matching rows in another table this relationship is defined as a one to many relationship. With Country(Pk_Country_Id) serving as the Primary key and UNrepresentative(fk_Country_id) as (Unique Key Constraint-Foreign Key), you can implement One-to-One Relationship. One-to-One (1:1) Relationship between Country-UNrepresentative Table CREATE TABLE Country ( Pk_Country_Id INT IDENTITY PRIMARY KEY, Name VARCHAR(100), Officiallang VARCHAR(100), Size INT(11), ) CREATE TABLE UNrepresentative ( Pk_UNrepresentative_Id INT PRIMARY KEY, Name VARCHAR(100), Gender VARCHAR(100), Fk_Country_Id INT UNIQUE FOREIGN KEY REFERENCES Country(Pk_Country_Id) ) INSERT INTO Country ('Name','Officiallang',’Size’) VALUES ('Nigeria','English',923,768) INSERT INTO Country ('Name','Officiallang',’Size’) VALUES ('Ghana','English',238,535) INSERT INTO Country ('Name','Officiallang',’Size’) VALUES ('South Africa','English',1,219,912) INSERT INTO UNrepresentative ('Pk_Unrepresentative_Id','Name','Gender','Fk_Country_Id') VALUES (51,'Abubakar Ahmad','Male',1) INSERT INTO UNrepresentative ('Pk_Unrepresentative_Id','Name','Gender','Fk_Country_Id') VALUES (52,'Joseph Nkrumah','Male',2) INSERT INTO UNrepresentative ('Pk_Unrepresentative_Id','Name','Gender','Fk_Country_Id') VALUES (53,'Lauren Zuma,'Female',3) SELECT * FROM Country SELECT * FROM UNrepresentative Let’s try out the implement and see for ourselves. This relationship can be created using Primary key-Unique foreign key constraints.įor instance a Country can only have one UN Representative, and also a UN Representative can only represent one Country. When a row in a table is related to only one role in another table and vice versa,we say that is a one to one relationship. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |