I am using C# ASP.NET on Visual Studio 2005, as well as SQL Server 2005.
Currently I have a project which requires me to check each user for any conflicting roles that they might posses.
I have 2 database. Users and ConflictingRoles. Below is the structure of the 2 tables:


In Users, I have 2 unique users with 4 roles each.
In ConflictingRoles, I have 4 rows of conflicing roles.
James and Jennifer each have 4 roles, and each of them is conflicting with one another.
I want to form multiple SQL queries, to check each role possessed by each user if they are in conflict with any other role which they posses.
I have a rough idea of how the process will be like, but I am not sure how to portray the idea using multiple SQL queries:
1) One row at a time, grep the value usr.UserID and usr.Role from Users usr table.
Store usr.UserID in to temporary variable tempUID, and find matching vales of usr.Role with cf.Role in ConflictingRoles cf table.
2) If usr.Role matches cf.Role, grep the value of cf.ConflictingRole and run through all usr.Role in Users table WHEREusr.UserID matches tempUID.
If a match/conflict is found between cf.ConflictingRole with usr.Role of user tempUID, insert cf.ConflictingRole, usr.Role and user.Name into a separate table, Results.
3) Repeat this for all roles that each user posses, and for all users.
Basically is that a user is not allowed to posses both roles which are conflicting each other. If they do, store the name, role and conflictingrole in a table.
It is very confusing for me and I am not sure if there is a simplier way to do it.
If not, I will like to request help from you guys with the SQL queries that I will have to form with my above logical sequence.
SqlConnection thisConnection = new SqlConnection("Data Source=DS");
SqlCommand nonqueryCommand = thisConnection.CreateCommand();
thisConnection.Open();
//multiple sql commands
nonqueryCommand.CommandText = "<SQL Query>";
Console.WriteLine(nonqueryCommand.ExecuteNonQuery());
...
Thank you for any help in advance.
First approach: