Imports System
Imports System.Data
Imports Microsoft.SqlServer.Server
Imports System.Data.SqlClient
Imports System.Data.SqlTypes


Public Class PubsTriggers
    ' used for trigger when rows are deleted from
    ' the jobs table. Deleted jobs are moved to
    ' the obsoletejobs table
 ' Enter existing table or view for the target and uncomment the attribute line
 ' <SqlTrigger(Name:="Trigger1", Target:="Table1", Event:="FOR UPDATE")> _
    Public Shared Sub AddToObsolete()
        ' get the trigger context so you can tell what is
        ' going on

        ' this trigger is for deletes

        ' Make a command

        ' make a command the inserts the deleted row into
        ' the obsoletejobs table

        ' move the rows

        Dim rowsAffected As Integer
        If rowsAffected = 0 Then
            ' something bad happened, rollback

        End If
    End Sub


    ' Used for trigger on authors table
    ' prevents the authors contract from
    ' being changed from 1 to 0 if any
    ' author (of those being updated) 
    ' has a book that pays a royality
    ' greater than 30.
    ' All publishers should have this
    ' trigger in their databases

 ' Enter existing table or view for the target and uncomment the attribute line
 ' <SqlTrigger(Name:="Trigger1", Target:="Table1", Event:="FOR UPDATE")> _
    Public Shared Sub AuthorCheckContract()
        ' get the trigger context for later

        ' this is used on for updates

        ' check to see if the contract is being changed
        ' from 1 to 0
        '

        Try
            If True = True Then
                ' if you get to here then at
                ' least one of the authors in
                ' those in the updated table
                ' had a book with a royalty 
                ' greater than 30

            End If
        Catch e As Exception
            ' do nothing, means contract was not part of the update statement
        End Try

    End Sub
End Class
