how to delete a row from a table that contains only one column ??? RRS feed

  • Question

  • User-1945703575 posted

    please help me 

    Monday, March 27, 2017 1:11 PM

All replies

  • User-1509636757 posted

    DELETE Query will still remain the same no matter how many columns are there in a table. For example, there is a table "TestTable" with a column "TestColumn" and there are 3 records with value "1","2" and "3" and you wanted to delete record with TestColumn value as "3" then your delete query will be:

    DELETE FROM TestTable WHERE TestColumn = '3'
    Monday, March 27, 2017 1:38 PM
  • User765422875 posted

    Basic syntax:

    DELETE FROM <tblName> where <columnId> = <Your Column Id val>
    Monday, March 27, 2017 2:08 PM
  • User-1945703575 posted

    i would like to delete any value not a precious value

    Monday, March 27, 2017 4:22 PM
  • User-1672470423 posted

    Your question is not clear can u give example what u are trying to do.

    Monday, March 27, 2017 4:43 PM
  • User-1945703575 posted

    for exemple i have a table name's "user"

    The table is filled with the following lines

    id                             name                           phone  

    1                              aaaaaa                         11111111

    2                              bbbbbb                        22222222

    3                              ccccccc                         33333333

    i chouse 1 or 2 or 3 to delete , i don't like to delete a precious line 

    Monday, March 27, 2017 4:55 PM
  • User-1509636757 posted

    Can you elaborate more on what do you mean by precious value? Do you mean any specific value? You may create a procedure for deleting by passing a parameter, to make it work for any value:

    CREATE PROCEDURE usp_DeleteRecord
        @RecToDelete VARCHAR(100)
        DELETE FROM TestTable WHERE TestColumn = @RecToDelete

    To call it:

    EXEC usp_DeleteRecord 'Test Val'

    Monday, March 27, 2017 5:17 PM
  • User-1672470423 posted

    Still not clear. But check below queries if it helps:

    1. Deleting the entire row 

    Declare @idtobedeleted Int

    Set @idtobedeleted = 1 -- it can be 1 or 2 or 3

    Delete From user Where id = @idtobedeleted

    2. Updating the row

    Declare @idtobeupdated Int

    Set @idtobeupdated= 1 -- it can be 1 or 2 or 3

    Update user

    Set name = null, phone = null -- or replace null with the values you want to populate

    Where id = @idtobeupdated

    Monday, March 27, 2017 5:35 PM
  • User765422875 posted

    Your question still  isn't clear. Do you want to delete multiple rows based on what is selected?

    Monday, March 27, 2017 5:36 PM
  • User-1945703575 posted


    Monday, March 27, 2017 6:38 PM
  • User-1672470423 posted

    Below query delete multiple records, you just need to pass ids as comma separated 

    Delete From user Where id in (1, 2, 3) -- if you want 1, 2, 3 to be deleted.

    Monday, March 27, 2017 6:43 PM