944,117 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 22295
  • MS SQL RSS
Apr 18th, 2006
0

Triggers Loop or Stored Procedures Loop

Expand Post »
Hi all
The problem is the following :
  • I am in a project that contains a table of users(user_tbl) and another table of groups(Group_tbl) . and each group can contains multi-user by Group_Id which is foreign key in user_tbl .
  • I am now about creating a trigger that happens when inserting in permissions_tbl (contains users and group permissions) . It should insert all users of the inserted group into the permissions_tbl also with the same values the group taked.
  • So , I need Loops very much to loop in the user_tbl and get the users of the inserted group then insert them in the permissions_tbl .

I wish if some one can help me .
Thank you very much
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
web developer is offline Offline
36 posts
since Mar 2006
Apr 18th, 2006
0

Re: Triggers Loop or Stored Procedures Loop

Boy you need to reed up on the relational model and set-theory. Loops don't belong in an RDBMS. (except in VERY exceptional circumstances)

Google or search some of these terms and start reading.

You don't need a trigger or a loop Yuck!

If you can supply more details on structure of your table and sample data, and what you need the result to be I could give you example TSQL code to do it.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Apr 18th, 2006
0

Re: Triggers Loop or Stored Procedures Loop

MS SQL Syntax (Toggle Plain Text)
  1. INSERT INTO
  2. permisions_tbl (userid)
  3. SELECT
  4. userid
  5. FROM
  6. user_tbl
  7. WHERE
  8. groupid = @groupid
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Apr 19th, 2006
0

Re: Triggers Loop or Stored Procedures Loop

Thank you very much
i will try that
but in general , how can i loop through a result set from a select statement in a trigger or in a stored procedures , that is needed for checking values and other comparisons when looping
Thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
web developer is offline Offline
36 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: inserting coloring text
Next Thread in MS SQL Forum Timeline: SQL Golf Handicap





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC