-- autoaudit v2 
-- options testing 

USE Adventureworks2008

go --------------------------------------------------------------------------------------------

EXEC pAutoAudit @SchemaName = 'HumanResources', 
                @TableName = 'Department',
                @StrictUserContext = 1,
                @LogSQL = 0,
                @BaseTableDDL = 0
                
go --------------------------------------------------------------------------------------------
-- INSERT TEST 

INSERT HumanResources.Department (Name, GroupName)
  VALUES ('DBA', 'IT')
  
SELECT * FROM HumanResources.Department WHERE DepartmentID >= 17

SELECT * FROM dbo.Audit

go --------------------------------------------------------------------------------------------

UPDATE HumanResources.Department
  SET Name = 'Newer Name',
      GroupName = 'G2'
  WHERE DepartmentID = 17
  
UPDATE HumanResources.Department
  SET Name = 'Newest Name',
      GroupName = 'G3'
  WHERE DepartmentID = 17
  
SELECT * FROM HumanResources.Department WHERE DepartmentID >= 17

SELECT * FROM dbo.Audit

SELECT * FROM HumanResources.Department_RowHistory(17)


go --------------------------------------------------------------------------------------------
-- DELETE 

DELETE HumanResources.Department   
  WHERE DepartmentID = 17   

--- 

SELECT * FROM HumanResources.Department WHERE DepartmentID >= 17 

SELECT * FROM audit

SELECT * FROM HumanResources.vDepartment_Deleted



