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

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

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE {databaseOwner}[{objectQualifier}tblNaDevEventTabs](
	[tabId] [int] IDENTITY(1,1) NOT NULL,
	[EventId] [int] NOT NULL,
	[listOrder] [int] NOT NULL,
	[tabName] [nvarchar] (255) not null,
	[tabContent] [ntext] not null
 CONSTRAINT [PK_{objectQualifier}tblNaDevEventTabs] PRIMARY KEY CLUSTERED 
(
	[tabId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF)
)

GO

ALTER TABLE {databaseOwner}[{objectQualifier}tblNaDevEventTabs]  WITH CHECK ADD  CONSTRAINT [FK_{objectQualifier}tblNaDevEventTabs_tblNaDevEvents] FOREIGN KEY([eventId])
REFERENCES {databaseOwner}[{objectQualifier}tblNaDevEvents] ([eventId])
ON DELETE CASCADE
GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventTabs_GetAll]
(
 @eventId int
)

as

	select * from {databaseOwner}[{objectQualifier}tblNaDevEventTabs] 
		where eventId = @eventId order by listOrder asc

return

GO

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

create procedure {databaseOwner}[{objectQualifier}usp_nadev_EventTabs_Delete]
(
  @tabId int
)

as

	delete {databaseOwner}[{objectQualifier}tblNaDevEventTabs] where tabId = @tabId 

return

GO

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

create procedure {databaseOwner}{objectQualifier}usp_nadev_EventTabs_Save
(
 @tabId int,
 @eventId int,
 @listOrder int,
 @tabName nvarchar (255),
 @tabContent ntext
)

as

set nocount on
  
 if exists(select null from {databaseOwner}[{objectQualifier}tblNaDevEventTabs] where tabId = @tabId)
	begin
		update {databaseOwner}[{objectQualifier}tblNaDevEventTabs] set eventId = @eventId,
																	   listOrder = @listOrder,
																	   tabName = @tabName,
																	   tabContent = @tabContent
																	   where tabId = @tabId
			end 
else
	insert into {databaseOwner}[{objectQualifier}tblNaDevEventTabs] (eventId,listOrder,tabName,tabContent)

	values (@eventId,@listOrder,@tabName,@tabContent)
	
	SELECT SCOPE_IDENTITY()

GO
