Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
USE [tempdb]
	 IF OBJECT_ID (N'#TempTable') IS  NULL
	 BEGIN
	BEGIN TRY
	 
 CREATE TABLE #TempTable
 (
  AuditUser varchar(36) not null default '',
   AuditIP varchar(39) not null default '',
   AuditNotes varchar(4000) not null default '',
   AuditClientUTC datetime not null default getutcdate(),
 )

 INSERT INTO #TempTable(AuditUser,AuditIP,AuditNotes,AuditClientUTC)
 values('','','',getutcdate())
 END TRY
 BEGIN CATCH
 SELECT ERROR_NUMBER() AS ErrorNumber;
 END CATCH
	END


USE [microCMMSTestNew]
GO
/****** Object:  Trigger [dbo].[trcmmsdeleteOperation]    Script Date: 21-05-2015 01:12:48 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [dbo].[trcmmsdeleteOperation]
   on [dbo].[Person]
   after  delete AS 
   begin
    declare @AuditServerUTC [datetime]

	INSERT INTO [dbo].[PersonAudit]
           ([fKeyBase]
           ,[AuditServerUTC]
           ,[AuditClientUTC]
           ,[AuditUser]
           ,[AuditIP]
           ,[AuditNotes]
           ,[FirstName]
		   ,[LastName]
		   ,[Status])
	select d.GUID
	,d.AuditServerUTC
	,d.AuditClientUTC
	,d.AuditUser
	,d.AuditIP
	,d.AuditNotes
	,d.FirstName
	,d.LastName
	,d.Status
	FROM Deleted d
	end


In the above SQl statements when I execute it's working but when this SQL script close the editor of SSMS only trigger is viewed but not before sql statements.
Posted
Updated 22-May-15 13:45pm
v2
Comments
Andrius Leonavicius 22-May-15 20:00pm    
Hi,

First of all, you are creating #TempTable, which is a local temporary table. This table is only available to the current connection for the user (in your case, a table will be dropped after closing SSMS editor). Temporary tables are used to store data temporarily during a transaction or session. What is the purpose of this temporary table?

Second, you have a trigger, which has nothing to do with the #TempTable. How these two things are related?

Could you tell me what exactly you are trying to achieve?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900