Triggers Loop or Stored Procedures Loop

Please support our MS SQL advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2006
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Triggers Loop or Stored Procedures Loop

 
0
  #1
Apr 18th, 2006
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
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Triggers Loop or Stored Procedures Loop

 
0
  #2
Apr 18th, 2006
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Triggers Loop or Stored Procedures Loop

 
0
  #3
Apr 18th, 2006
  1. INSERT INTO
  2. permisions_tbl (userid)
  3. SELECT
  4. userid
  5. FROM
  6. user_tbl
  7. WHERE
  8. groupid = @groupid
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 36
Reputation: web developer is an unknown quantity at this point 
Solved Threads: 0
web developer's Avatar
web developer web developer is offline Offline
Light Poster

Re: Triggers Loop or Stored Procedures Loop

 
0
  #4
Apr 19th, 2006
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
Life Is A Big Code
Rushdy Ibrahim
Egypt
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC