December 14, 2013 at 12:29 pm
How can you create foreign key relation to the same table which contains primary key.
December 14, 2013 at 4:44 pm
ramana3327 (12/14/2013)
How can you create foreign key relation to the same table which contains primary key.
So you're doing a self-join? Like in an Employee/Manager scenario?
See this article: http://msdn.microsoft.com/en-us/library/ms190273.aspx
Section E.
there are examples of creating primary and foreign key constraints.
December 16, 2013 at 10:06 am
How?
Yep, I can create like below...
CREATE TABLE Emp(
EmpID INT PRIMARY KEY,
Emp_Name VARCHAR(100),
Emp_JoinDate DATE,
Emp_Salary Money,
Emp_Designation Varchar(50),
Emp_ManagerID INT FOREIGN KEY REFERENCES Employee(EmpID)
)
You may get issues while inserting into Emp_ManagerID , you may use null value for that.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply