How to insert foreign key values

Posted by Self-innovator under Sql Server on 1/9/2012 | Points: 10 | Views : 1815 | Status : [Member] | Replies : 7
Hi dear all ,
i've question table in which i've 2 columns code(id) and questions
i've one more table called rating in which i've two columns QnCode(pk,fk) and Rating..here i want to insert the rating values in rating table based on question code using sp..how do i do this my friend said it is possible by using split function to get code from question table and store..pls help me to generate the sp it urgent..

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down
Kindly describe your requirement

Thanks,
Sanjay

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down
i've posted another question in forum briefly pls go through...

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down




create table questionMaster
(qid int,qText varchar(300))
insert into questionMaster values(1,'What is your name')
insert into questionMaster values(2,'What is your favorite color')
insert into questionMaster values(3,'What is your Hobby')

create table Rating
(ID int,Rating int,Qid int)

create procedure spRating
(@Rating int,@Qid int)
as
Begin
Declare @ID int
select @ID=isnull(0,MAX(id))+1 from Rating
insert into Rating(ID,Qid,Rating) values(@ID,@Rating,@Qid)
End

-- check
--pass right value from frontend
-- spRating 1,2

Thanks,
Sanjay

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down
i've seperate question table with QstnCode and QstnDescription i want to insert the rating in rating table according to question code..

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down

yes , if qid is foreign key in Rating table.
That means while we enter qid it should have existence in QuestionMaster Table.

So in the front end you show the qid and text in a dropdown.
So that only existing value can go to rating table.
In the dropdown the the Datavaluefield will be qid and DataTextField will be QuestionText.

Thanks,
Sanjay

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down
it's better if u go through my another post in the forum where i've explained briefly...

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down
ok let go through it

Thanks,
Sanjay

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response