
-- SQLAzureMWParseTSQL TSQL Output File:
-- Generated at: 3/1/2014 3:07:20 PM

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table {databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications]
GO

CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications] (
	[Id] [int] IDENTITY (1, 1) NOT NULL ,
	[eventId] [int]NOT NULL,
	[emailAddress] [nvarchar] (255)NOT NULL,
	[remindDate] [datetime] not null
    constraint [PK_{objectQualifier}tblNaDevEventsUserNotifications] primary key clustered
	(
		[Id] asc
	)
)
GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_insertEventsUserNotifications]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_insertEventsUserNotifications
GO

create procedure {databaseOwner}{objectQualifier}usp_insertEventsUserNotifications
(
 @eventId int,
 @emailAddress nvarchar(255),
 @remindDate datetime
)

as

set nocount on
  
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications] (eventId, emailAddress,remindDate)

	values (@eventId, @emailAddress,@remindDate)

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_deleteUserNotificationForEvent]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_deleteUserNotificationForEvent
GO

create procedure {databaseOwner}{objectQualifier}usp_deleteUserNotificationForEvent
(
 @Id int
)

as

set nocount on
  
	delete from {databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications] where id = @id

GO

if exists (select * from dbo.sysobjects where id = object_id(N'{databaseOwner}[{objectQualifier}usp_getAllUserNotificationsToSend]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	drop procedure {databaseOwner}{objectQualifier}usp_getAllUserNotificationsToSend
GO

create procedure {databaseOwner}{objectQualifier}usp_getAllUserNotificationsToSend

as

set nocount on
  
	select * from {databaseOwner}[{objectQualifier}tblNaDevEventsUserNotifications] where remindDate < getDate()

GO
