Triggers created by ERWin

I am using ERWin to create tables and ERWin creates update and insert triggers, apparently to maintain integrity. Are they really needed to maintain integrity? Should I turn off the feature?

Also, here is some code from an insert trigger that ERWin created.



create trigger tI_tblAR on tblAR for INSERT as
/* ERwin Builtin Tue Jul 27 17:31:08 1999 */
/* INSERT trigger on tblAR */
begin
  declare  @numrows int,
           @nullcnt int,
           @validcnt int,
           @errno   int,
           @errmsg  varchar(255)

  select @numrows = @@rowcount
  /* ERwin Builtin Tue Jul 27 17:31:08 1999 */
  /* tblMain R/97 tblAR ON CHILD INSERT RESTRICT */
  if
    /* %ChildFK(" or",update) */
    update(MainID)
  begin
    select @nullcnt = 0
    select @validcnt = count(*)
      from inserted,tblMain
        where
          /* %JoinFKPK(inserted,tblMain) */
          inserted.MainID = tblMain.MainID
    /* %NotnullFK(inserted," is null","select @nullcnt = count(*) from inserted where"," and") */
   
    if @validcnt + @nullcnt != @numrows
    begin
      select @errno  = 30002,
             @errmsg = 'Cannot INSERT tblAR because tblMain does not exist.'
      goto error
    end
  end

  /* ERwin Builtin Tue Jul 27 17:31:08 1999 */
  /* tblARType R/79 tblAR ON CHILD INSERT RESTRICT */
  if
    /* %ChildFK(" or",update) */
    update(ARType)
  begin
    select @nullcnt = 0
    select @validcnt = count(*)
      from inserted,tblARType
        where
          /* %JoinFKPK(inserted,tblARType) */
          inserted.ARType = tblARType.ARType
    /* %NotnullFK(inserted," is null","select @nullcnt = count(*) from inserted where"," and") */

1)What is update(MainID)
2)In the statement, 'from inserted, tblMain', what is inserted? Is it a table?

I can paste the rest of the code for the insert trigger and the update trigger if needed.

Musleh
mfarid1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BennyBunnyCommented:
Inserted:
Inserted is the "table" where all of the information ( DATA ) is stored which the insert  affects
and IF update (mainid) means:
if the coloumn mainid is affected ( chaged) by the statement ( insert ) then do the other stuff


cya BB
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mfarid1Author Commented:
BennyBunny, thank you for your partial answer but my other questions were:

Are the ERWin triggers really needed to maintain integrity? Should I turn off the feature? I already have constraints which I create.

Musleh
0
Gustavo Perez BuenrostroCommented:
mfarid1,

ERwin triggers are not needed to enforce referential integrity between the foreign key columns and the related primary key (or UNIQUE constraint) columns in another table.
Remember that constraints are checked prior to trigger execution. It means you must drop all constraints to see triggers work when these two mechanisms for enforcing business rules and data integrity exist.
Turn off the feature.
For more information, see "Triggers Compared to Other Data Integrity Methods" topic in BOL.
0
mfarid1Author Commented:
Here are half the points for half the answer. I am giving the other half to gpbuenrostro
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.