对于每个student_id,在我的答案表中应该是唯一的question_id [英] for each student_id threre should be unique question_id in my answer table

查看:115
本文介绍了对于每个student_id,在我的答案表中应该是唯一的question_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有桌子答案列是

ans_id身份证//主键

question_id外键

student_id外键

回答varchar(500)



所以如何查询或任何需要的设置

i正在开发应用程序ASP.Net with C#

解决方案

在表设计器中

选择question_id

和student_id

并用鼠标右键单击设计器左侧

打开上下文菜单设置主键。







设置主键后,

现在只能保存不同的值。


看到我写了一个storeprocedure它应该是这样的我不知道你的表名,我只是研究你的对话和程序这样的事情

创建程序usp_QuestionAnswer 
{
@question_id int = 0,
@student_id int = 0,
@answer varchar(500)= null
}
AS BEGIN
//检查数据是否存在
如果不存在(从tblQuestionAnswer选择question_id = question_id = @question_id和student_id = @ student_id)开始
插入到tblQuestionAnswer(question_id,student_id,answer)
values(@question_id,@ student_id,@ answer)

end

END


i have table Answer colums are
ans_id identity key //primary key
question_id foreign key
student_id foreign key
answer varchar(500)

so how to query or any kind of setting needed
i am developing application ASP.Net with C#

解决方案

In Table Designer
Select question_id
And student_id
And Right Click on Left Side Of Designer With Your Mouse
To Open Context Menu To Set Primary Key.



Once You Set Primary Key,
Now Only Distinct Value Can Be Save .


See I have written a storeprocedure it should something like this I don't know your table name, I just studied your conversation and procedure something like this

create procedure usp_QuestionAnswer
{
@question_id int=0 ,
@student_id int =0,
@answer varchar(500)=null
}
AS BEGIN
//Check if data exists or not
if not exists(select question_id from tblQuestionAnswer where question_id = @question_id  and  student_id =@student_id  ) begin
   insert into tblQuestionAnswer(question_id ,student_id,answer)
   values(@question_id ,@student_id,@answer)

end

END


这篇关于对于每个student_id,在我的答案表中应该是唯一的question_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆