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

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

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

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

CREATE TABLE [dbo].[Advertisement] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[AdImage] [varchar] (75) NOT NULL ,
	[AdVoice] [varchar] (75) NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Answer] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[questionID] [int] NOT NULL ,
	[TextAnswer] [varchar] (500) NOT NULL ,
	[VoiceAnswer] [varchar] (75) NOT NULL ,
	[AnswerCount] [int] NOT NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Question] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[TextQuestion] [varchar] (500) NOT NULL ,
	[VoiceQuestion] [varchar] (75) NULL ,
	[VoiceOptions] [varchar] (75) NULL ,
	[StartDate] [datetime] NOT NULL ,
	[EndDate] [datetime] NOT NULL ,
	[VoiceAd] [varchar] (75) NULL ,
	[TextAd] [varchar] (75) NULL 
) ON [PRIMARY]
GO

SET QUOTED_IDENTIFIER  ON    SET ANSI_NULLS  ON 
GO

CREATE PROCEDURE [Increment_AnswerCount  ] 
	@AnswerID INT 
AS 
BEGIN
	UPDATE answer SET AnswerCount = AnswerCount +1  WHERE ID=@AnswerID
END
GO
SET QUOTED_IDENTIFIER  OFF    SET ANSI_NULLS  ON 
GO

