本文介绍了使用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

推荐答案


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

08-05 22:20