Q. Can Primary key is a Foreign Key on the same table?



Answer: Yes, Primary key can act as  a Foreign Key on the same table.
For Example:-

CREATE TABLE T (
   GroupID int not null,
   ItemID int not null,
   ParentItemID int null,
   constraint PK_T PRIMARY KEY (GroupID,ItemID),
   constraint FK_T_Parent FOREIGN KEY (GroupID,ParentItemID) 
 references T (GroupID,ItemID)
)

0 comments:

Post a Comment