使用sql查询向用户分配角色 [英] assigning roles to user using sql query

查看:100
本文介绍了使用sql查询向用户分配角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为用户分配角色..

我有三个表用户(用户名,密码,用户名)

和群组(groupid,rolename)

角色(groupid,userid)

就是这样的sql查询


从角色WHERE组ID = 3和用户ID = 3的SELECT COUNT(*)转换为v_count;

如果v_count = 0
然后将角色插入(groupid,userid)值(3,4);




我之前尝试过的查询是这个..这是错误的



查询应该像这样.
帮助我更正该查询的语法.

如果userid和groupid已经起作用.它将选择它们,否则将插入它们.

从users.username = chirstian和groups.rolename = admin
的角色中选择roles.userid,roles.groupid 否则在角色中插入userid和groupid,其中users.username = chirstian和groups.rolename = admin

i want to assign roles to users..

i have three tables users ( username, password, userid)

and groups( groupid, rolename)

role( groupid ,userid)

iss the sql query like this


SELECT COUNT(*)into v_count from roles WHERE groupid = 3 and userid=3;

IF v_count = 0
THEN INSERT INTO roles( groupid, userid) VALUES (3,4);




The Query i tried earlier is this.. which is wrong



query should be just like this.
help me to correct the syntax of that query.

if the userid and groupid are already in role.. it will select them otherwise it will insert them.

select roles.userid, roles.groupid from roles where users.username=chirstian and groups.rolename=admin
else insert userid and groupid in role where users.username=chirstian and groups.rolename=admin

推荐答案

哦,天哪.在新帖子中,不要一遍又一遍地问同样的问题.发表您的问题,并根据需要对其进行编辑以添加详细信息.或者只是首先要完全清楚地询问它.这太琐碎了,我真的不知道有谁能比我已经做过的更充分地解释它.

您将进行选择计数,检查它是否为0,然后插入.再次,请勿插入名称,请插入ID.我的CP ID是6556.如果我要更改显示的名称,则数据库应该可以使用,不要使用我的名字,而是使用我的ID,以解决与帐户相关的任何其他问题.
Oh, good lord. Stop asking the same question over and over, in new posts. Post your question, and edit it to add detail if needed. Or just ask it fully and clearly in the first place. This is so trivial, I really don''t know what anyone can do to explain it more fully than I have done already.

You would do a select count, check if it is 0, and then insert. Again, do NOT insert the names, insert the IDs. My CP id is 6556. If I were to change my displayed name, the database should be fine with that, by not using my name, but my id, for anything else tied to my account.


这篇关于使用sql查询向用户分配角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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