K
K
Konstantin Tsvetkov2021-09-28 11:06:35
SQL Server
Konstantin Tsvetkov, 2021-09-28 11:06:35

How to delete a specific entry or group in one request?

Table of options for naming various objects.

CREATE TABLE [dbo].[Variation](
  [ID] [int] IDENTITY(1,1) NOT NULL,
  [Kind] [char](1) NOT NULL,
  [Object] [int] NOT NULL,
  [Value] [varchar](500) NOT NULL,
  [Key]  AS ([Kind]+CONVERT([varchar],[object]))
)

How to delete a single entry or all entries for a specific object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Konstantin Tsvetkov, 2021-09-28
@tsklab

CREATE PROCEDURE VariationDelete @KEY VARCHAR(10), @ID INT = -1
AS
  DELETE FROM [Variation]
    WHERE ([Key] = @KEY) AND ((@ID = -1 ) OR (ID = @ID ))
--
GO

When not specified @ID, all entries are deleted by @KEY, when specified, only one entry.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question