Need Help for foreign key Constraint Query [Resolved]

Posted by Yashodajagalur under Sql Server on 3/1/2012 | Points: 10 | Views : 946 | Status : [Member] | Replies : 7
Can any one give the example of Foreign key Constraint with SQL Query for the below example?
for example, an employee table that contains three columns: employee_number, employee_name, and manager_employee_number. Because the manager is an employee too, there is a foreign key relationship from the manager_employee_number column to the employee_number column.

Thanks




Responses

Posted by: Avdesh on: 3/1/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
YOU CAN ALSO WORK LIKE THIS
create table employee(empno int primary key,empname varchar(20),MgrEmpno int foreign key references employee(empno))
it references the the same table employee
Thanks And Regards
Avdesh

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kk86kiran on: 3/1/2012 [Member] Starter | Points: 25

Up
0
Down
if there is two tables i.e, employee and manager. First you have to create primary key for employee table
for example:

create table employee(employeename varchar(20),employeeNumber int constraint pk_Eno primary key, mangerEmpolyeeNumber int)


create table manger(EmployeeName varchar(20),mangerEmployeeNumber int constraint fk_mEmpNo foreign key reference employee(managerEmployeeNumber))






k.m.j.kiran

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Yashodajagalur on: 3/2/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks for the help

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Yashodajagalur on: 3/2/2012 [Member] Starter | Points: 25

Up
0
Down
Can any one help me on WPF,I need proper code for the below query

1)We have three fields like FirstName,LastName and Age in the designer page after compilation

In the Main Page(Output or resulting page) only Name and Age Should Display

(I tried using concatenation of strings but I didn't get it)

(Name=FirstName + LastName) and it can't be editable.

How can we do that in WCF

Thanks & Regards
Yashoda

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Avdesh on: 3/2/2012 [Member] Starter | Points: 25

Up
0
Down
PLEASE MARK AS ANSWER WHOSOEVER ANSWER IS CORRECT
THANKS AND REGARDS
AVDESH

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Yashodajagalur on: 3/3/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Avhesh

u r query is for creating table with FK Constraint.But i want sql query which retrives all the data from the table using only FK.
How can we write a query for that?

Thanks & Regards
YGirish

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/20/2012 [Member] Starter | Points: 25

Up
0
Down
PRIMARY KEY TABLE:

CREATE TABLE EMP(EMPID INT CONSTRAINT PK_EMP PRIMARY KEY(EMPID) ,EMPNAME VARCHAR(90))

FOREIGN KEY TABLE:

CREATE TABLE EMPSALARY(EMPID INT REFERENCES EMP(EMPID),EMPSALARY MONEY)

HOPE THIS WILL HELP

REGARDS

SRIRAM.R

sriram

Yashodajagalur, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response