Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 15-Aug-11 3:14am
v2

1 solution

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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900