-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: Gogi7735
Message 5 in Discussion

hi Vinod,               i am creating the trigger on the oracle table from VB.net 
Function that accepts table name ,in that function i have written code for the trigger 
cretaion using Command objects  ExecuteNonQuery method.this function will be invoked 
by the client application for a particular event. The Trigger code in oracle is as 
follows --Row level Trigger on the table DEPT --Track table is RS_REPORT  
CREATE OR REPLACE TRIGGER TR_DEPT 
AFTER INSERT OR UPDATE OR DELETE ON DEPT 
FOR EACH ROW  
DECLARE COUNTER NUMBER:=0;  
BEGIN  
IF INSERTING THEN  
INSERT INTO RS_REPORT VALUES (RS_REPORT_SLNO.NEXTVAL,:NEW.ROWID,'DEPT','I',0,0);  
END IF;  
IF UPDATING THEN  
SELECT COUNT(*) INTO COUNTER FROM RS_REPORT WHERE RS_REPORT_TABLENAME = 'DEPT' 
AND RS_REPORT_ROWID=:NEW.ROWID AND RS_REPORT_STATUS IN (0,1); 
IF(COUNTER <= 0 ) THEN  
INSERT INTO RS_REPORT VALUES (RS_REPORT_SLNO.NEXTVAL,:NEW.ROWID,'DEPT','U',0,0);  
END IF; 
END IF;  
IF DELETING THEN  
DELETE FROM RS_REPORT WHERE RS_REPORT_TABLENAME ='DEPT' AND RS_REPORT_ROWID=:NEW.ROWID 
AND RS_REPORT_STATUS =0; 
END IF;  
END; 
i have generalized the trigger creation for  oracle tables.(task became easier because 
of rowid) 
Now the problem shifts to SQL Server to write generic trigger creation given table 
table for a vb.net function 
i have reached up to identying the primary key columns  and struck at getting the 
primary key column value 
The code for sql triger i have written is 
CREATE TRIGGER TR_SAM
ON sam
FOR INSERT,UPDATE
AS
declare @V_KEY1 varchar(100)
declare @V_DATAKEY varchar(100)
declare @V_PRIMVAL varchar(100)
declare @V_KEY2 smallint
declare @V_RecNo int
declare @strQry as varchar(500)
create table #TPKEYS
(
   TABLE_QUALIFIER varchar(75),
   TABLE_OWNER varchar(20),
   TABLE_NAME varchar(100),
   COLUMN_NAME varchar(150),
   KEY_SEQUENCE smallint,
   PK_NAME varchar(75)
)
create table #TPValues
(
   colValues varchar(200)
)
insert into #TPKEYS exec sp_pkeys @table_name ='sam' 
SET  @V_RecNo = (Select Count(*) FROM  #TPKEYS)
if(@V_RecNo >1) 
  begin
  PRINT 'more than 1'
 end
else
 begin
SET @V_KEY1 = (SELECT COLUMN_NAME FROM  #TPKEYS )
PRINT '@V_KEY1'[EMAIL PROTECTED] 
-----Struck here to het the primary key column value
SET @V_DATAKEY = (SELECT   @V_KEY1   FROM  INSERTED  )  
print 'Primary key Value '[EMAIL PROTECTED]
end 
i am not  a dedicated database guy execuse me for not following the coding 
conventions. 
Regards 
-Srini 
  
  
  
     

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you received 
this message by mistake, please click the "Remove" link below. On the pre-addressed 
e-mail message that opens, simply click "Send". Your e-mail address will be deleted 
from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to