【问题标题】:sql server roles with condition具有条件的 sql server 角色
【发布时间】:2018-03-21 11:02:41
【问题描述】:

我的数据库中有两个表,第一个名为 “Students”,其中包含学生的信息,第二个表名为 “Study results”,其中包含结果学生的(每张表的结构如下)

==> 表学生

id_student || name_student ||学生年龄 ||缺席学生

==> 表格研究结果

id_result || id_student ||主题结果 ||标记

我希望每个学生都可以检查他的分数,所以我将允许他只从表 “学习结果” 中选择,但我也希望学生只看到他的分数而不是其他学生的标记,例如 [select * from Study results where idstudent=student_a]

我可以这样做吗? 我希望你能理解我的问题。 提前致谢

【问题讨论】:

  • 如何知道当前用户的id_student?有什么功能什么的吗?
  • 登录的学生我会得到他的id
  • 与在表上选择权限相比,使用存储过程实施安全性更容易。
  • 你能解释一下我不认为我明白吗

标签: c# asp.net sql-server sql-server-2012


【解决方案1】:

您应该创建一个存储过程或返回用户标记的函数。例如:

CREATE PROC GetUserMarks
    @UserId     INT
AS

DECLARE @pUserId INT = @UserId

SELECT subject_result, mark
FROM [study result]
WHERE id_student = @pUserId

然后使用当前用户的id_student作为变量@UserId运行它

【讨论】:

    猜你喜欢
    • 2014-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-14
    • 1970-01-01
    • 2016-07-28
    • 2021-06-25
    • 1970-01-01
    相关资源
    最近更新 更多