Click here to Skip to main content
15,887,683 members
Home / Discussions / Database
   

Database

 
Questioncan a trigger have parameters Pin
yousefshokati21-Nov-11 19:42
yousefshokati21-Nov-11 19:42 
AnswerRe: can a trigger have parameters? Pin
Shameel21-Nov-11 22:51
professionalShameel21-Nov-11 22:51 
AnswerRe: can a trigger have parameters Pin
Corporal Agarn22-Nov-11 3:01
professionalCorporal Agarn22-Nov-11 3:01 
GeneralRe: can a trigger have parameters Pin
yousefshokati22-Nov-11 19:33
yousefshokati22-Nov-11 19:33 
GeneralRe: can a trigger have parameters Pin
SilimSayo23-Nov-11 10:59
SilimSayo23-Nov-11 10:59 
GeneralRe: can a trigger have parameters Pin
yousefshokati23-Nov-11 19:56
yousefshokati23-Nov-11 19:56 
GeneralRe: can a trigger have parameters Pin
Chris Meech24-Nov-11 5:05
Chris Meech24-Nov-11 5:05 
GeneralRe: can a trigger have parameters Pin
SilimSayo24-Nov-11 6:18
SilimSayo24-Nov-11 6:18 
I would create a stored procedure that takes two parameters: personnel code and the amount by which to update the personnel balance. I would also use a transaction to ensure that no two users update the same record at the same time

SQL
CREATE PROCEDURE updateBalace 
@personnelCode int--could be other datatype
@amount decimal--could be real, money or whatever
AS

SET @actionAmount decimal=100.00

BEGIN TRAN
   UPDATE Personnel SET Balance=Balance+Amount WHERE PersonnelCode=@personnelCode

   IF EXISTS(SELECT Balance FROM Personnel WHERE Balance>@actionAmount AND
             PersonnelCode=@personnelCode)--Check if updated record exceeds certain balance
   BEGIN
      --Insert record into turnsTable and play some funky music :) 

   END

--check for errors
IF @@ERROR >0 
  ROLLBACK TRAN
ELSE
  COMMIT TRAN


My code is not kosher but you get the general idea.
GeneralRe: can a trigger have parameters Pin
Chris Meech24-Nov-11 6:29
Chris Meech24-Nov-11 6:29 
GeneralRe: can a trigger have parameters Pin
SilimSayo24-Nov-11 10:14
SilimSayo24-Nov-11 10:14 
AnswerRe: can a trigger have parameters Pin
vankireddy satish25-Nov-11 2:36
vankireddy satish25-Nov-11 2:36 
QuestionSQL Connection Error Pin
webpeon8020-Nov-11 13:56
webpeon8020-Nov-11 13:56 
AnswerRe: SQL Connection Error Pin
webpeon8020-Nov-11 14:53
webpeon8020-Nov-11 14:53 
AnswerRe: SQL Connection Error Pin
thatraja23-Nov-11 20:05
professionalthatraja23-Nov-11 20:05 
Questionhow to make self backup to sql-server-2008 ? Pin
Gali197820-Nov-11 7:57
Gali197820-Nov-11 7:57 
AnswerRe: how to make self backup to sql-server-2008 ? Pin
Mycroft Holmes20-Nov-11 12:09
professionalMycroft Holmes20-Nov-11 12:09 
AnswerRe: how to make self backup to sql-server-2008 ? Pin
Corporal Agarn21-Nov-11 9:23
professionalCorporal Agarn21-Nov-11 9:23 
QuestionShould every table have Primary key ? Pin
yousefshokati20-Nov-11 0:48
yousefshokati20-Nov-11 0:48 
AnswerRe: Should every table have Primary key ? Pin
Jörgen Andersson20-Nov-11 3:48
professionalJörgen Andersson20-Nov-11 3:48 
AnswerRe: Should every table have Primary key ? Pin
Eddy Vluggen20-Nov-11 7:11
professionalEddy Vluggen20-Nov-11 7:11 
AnswerRe: Should every table have Primary key ? Pin
Mycroft Holmes20-Nov-11 12:06
professionalMycroft Holmes20-Nov-11 12:06 
AnswerRe: Should every table have Primary key ? Pin
SilimSayo22-Nov-11 10:46
SilimSayo22-Nov-11 10:46 
GeneralRe: Should every table have Primary key ? Pin
yousefshokati22-Nov-11 21:38
yousefshokati22-Nov-11 21:38 
GeneralRe: Should every table have Primary key ? Pin
SilimSayo23-Nov-11 9:35
SilimSayo23-Nov-11 9:35 
GeneralRe: Should every table have Primary key ? Pin
SilimSayo23-Nov-11 9:37
SilimSayo23-Nov-11 9:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.