Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2013
    Posts
    30

    Answered: Simple Store Procedure to delete rows in SQL Server 2014

    Hello,

    I want to create a store procedure, which I have never done before and intimidating. I want to delete all the rows in a table my coding will be below


    USE [ATAS00_app]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    --Delete rows in General Ledger table

    DELETE dbo.GLDetl


    Do I need to add/code anything else will the table be close automatically? Do I have to worry about anything maintenance on the table? Thank you in advance

  2. Best Answer
    Posted by johnwalker10

    "CREATE PROCEDURE dbo.sp_CaseStudy_DEL_byPK
    @id INT
    AS
    BEGIN
    SET NOCOUNT ON

    DELETE
    FROM caseStudy
    WHERE
    id = @id

    END"


  3. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    I think you should read this article from the sql server documentation. Also if you are concerned about performance and your delete statement truly has no WHERE clause you might want to check out TRUNCATE TABLE.
    https://msdn.microsoft.com/en-us/library/ms187926.aspx

  4. #3
    Join Date
    Mar 2013
    Posts
    30
    Quote Originally Posted by Thrasymachus View Post
    I think you should read this article from the sql server documentation. Also if you are concerned about performance and your delete statement truly has no WHERE clause you might want to check out TRUNCATE TABLE.
    https://msdn.microsoft.com/en-us/library/ms187926.aspx



    Thanks Thrasymachus I appreciate the tip.

  5. #4
    Join Date
    Jan 2016
    Posts
    24
    Provided Answers: 1
    CREATE PROCEDURE dbo.sp_CaseStudy_DEL_byPK
    @id INT
    AS
    BEGIN
    SET NOCOUNT ON

    DELETE
    FROM caseStudy
    WHERE
    id = @id

    END

  6. #5
    Join Date
    Mar 2013
    Posts
    30
    Thanks Johnwalker10,

    This is what I am looking for. Thanks again.

  7. #6
    Join Date
    Jan 2016
    Posts
    24
    Provided Answers: 1
    your welcome

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •