Click here to Skip to main content
16,005,169 members
Home / Discussions / Database
   

Database

 
GeneralRe: Please help totally lost on syntax Pin
MeterMan24-Mar-06 4:36
MeterMan24-Mar-06 4:36 
GeneralRe: Please help totally lost on syntax Pin
Michael Potter24-Mar-06 4:50
Michael Potter24-Mar-06 4:50 
GeneralRe: Please help totally lost on syntax Pin
MeterMan24-Mar-06 4:43
MeterMan24-Mar-06 4:43 
GeneralRe: Please help totally lost on syntax Pin
Michael Potter24-Mar-06 4:52
Michael Potter24-Mar-06 4:52 
GeneralRe: Please help totally lost on syntax Pin
MeterMan24-Mar-06 6:25
MeterMan24-Mar-06 6:25 
GeneralRe: Please help totally lost on syntax Pin
Michael Potter24-Mar-06 8:39
Michael Potter24-Mar-06 8:39 
GeneralRe: Please help totally lost on syntax Pin
MeterMan25-Mar-06 12:43
MeterMan25-Mar-06 12:43 
QuestionDelete Procedure Pin
shapper24-Mar-06 3:28
shapper24-Mar-06 3:28 
Hello,

I am creating my first procedures in SQL using SQL 2005.
I have 3 tables, with the following columns:

Surveys - [SurveyId](PK) and [SurveyName] Questions - [SurveyId](FK), [SurveyQuestionId](PK) and [SurveyQuestion] Answers - [SurveyQuestionId](FK), [SurveyAnswerId](PK) and [SurveyAnswer]

Each survay can include various questions and each question can include several answers.
This is way I am using the Foreign Keys in both Questions and Answers tables. To relate the tables.

I created a procedure which deletes a Survey given its SurveyId. This is part is done.

I also need to delete all the questions dependent on that survey and all the answers dependent on those questions.
How can I delete survey, its questions and their answers when receiving the SurveyId?

Thank You Very Much,
Miguel

Here is the code of the procedure that I created which in this moment only deletes the survey from the Surveys table:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[Surveys_DeleteSurvey]

-- Procedure Parameters
@SurveyId As uniqueidentifier

AS
BEGIN

-- Check if SurveyId is null
IF( @SurveyId IS NULL )
RETURN -1
ELSE
BEGIN
-- Return '-1' if a survey with SurveyId given value is not found
IF( NOT EXISTS( SELECT @SurveyId FROM dbo.Surveys WHERE @SurveyId = SurveyId ) )
RETURN -1
END

-- Delete the survey with SurveyId given value
DELETE FROM dbo.Surveys WHERE @SurveyId = SurveyId

-- Return '0' when successful
RETURN 0

END

AnswerRe: Delete Procedure Pin
Michael Potter24-Mar-06 4:10
Michael Potter24-Mar-06 4:10 
QuestionSQL Server over Virtual Private Network Pin
StyleGuide24-Mar-06 0:08
StyleGuide24-Mar-06 0:08 
AnswerRe: SQL Server over Virtual Private Network Pin
Luis Alonso Ramos24-Mar-06 5:45
Luis Alonso Ramos24-Mar-06 5:45 
GeneralRe: SQL Server over Virtual Private Network Pin
StyleGuide26-Mar-06 6:21
StyleGuide26-Mar-06 6:21 
GeneralRe: SQL Server over Virtual Private Network Pin
Luis Alonso Ramos26-Mar-06 17:47
Luis Alonso Ramos26-Mar-06 17:47 
QuestionLogin ID and Password Pin
mrkeivan23-Mar-06 11:00
mrkeivan23-Mar-06 11:00 
AnswerRe: Login ID and Password Pin
Krisky23-Mar-06 17:39
Krisky23-Mar-06 17:39 
AnswerHEY i did what you said Pin
mrkeivan23-Mar-06 23:21
mrkeivan23-Mar-06 23:21 
AnswerRe: Login ID and Password Pin
Michael Potter24-Mar-06 4:36
Michael Potter24-Mar-06 4:36 
AnswerRe: Login ID and Password Pin
Luis Alonso Ramos26-Mar-06 17:49
Luis Alonso Ramos26-Mar-06 17:49 
QuestionVisio Pin
devfendar23-Mar-06 7:43
devfendar23-Mar-06 7:43 
QuestionQuery the MaxLocksPerFile Count. Pin
beatle1123-Mar-06 3:45
beatle1123-Mar-06 3:45 
QuestionTransfer sql server database to ms access in vb 6.0... Pin
swirldan23-Mar-06 1:04
swirldan23-Mar-06 1:04 
Questionwhat is wrong in this code Pin
mm31022-Mar-06 23:03
mm31022-Mar-06 23:03 
AnswerRe: what is wrong in this code Pin
albCode22-Mar-06 23:31
albCode22-Mar-06 23:31 
AnswerRe: what is wrong in this code Pin
Colin Angus Mackay23-Mar-06 1:34
Colin Angus Mackay23-Mar-06 1:34 
QuestionUnable to run the SQL Server critical update Pin
Suj_7822-Mar-06 23:03
Suj_7822-Mar-06 23:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.