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

Related Posts:

  • Fuzzy logic Fuzzy logic Fuzzy logic is an approach to computing based on "degrees of truth" rather than the usual "true or false" (1 or 0) Boolean logic on which the modern computer is based. Example Fuzzy set theory defines fuzzy ope… Read More
  • Query to find the Rank or Position SELECT Name, Marks, ( SELECT COUNT(*)+1 FROM Student B WHERE A.Marks<B.Marks) AS Rank FROM Student AORDER BY Marks DESC Output is:     To See the Table Values Click here … Read More
  • Difference between Store Procedure and Trigger? Difference between Store Procedure and Trigger? We can call stored procedure explicitly. But trigger is automatically invoked when the action defined in trigger is done.      ex: create trigger aft… Read More
  • SQL SQLObjective type Questions SQLObjective type Question and Answers Set 1  Click here 1.       What does SQL stand for? a.         Structured Query Language b. &… Read More
  • What is the difference between oracle,sql and sql server ? What is the difference between oracle,sql and sql server ? •Oracle is based on RDBMS. •SQL is Structured Query Language. •SQL Server is another tool for RDBMS provided by MicroSoft. … Read More

0 comments:

Post a Comment