delete statement using store procedure

Shambhu Rai 1,381 Reputation points
2023-01-26T16:36:08.3833333+00:00

how can use delete statement for SP

create table table1( col int,col2 varchar(200))

create sp as

(

delete from table1 where condition

)

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,234 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,403 questions
SQL Server Analysis Services
SQL Server Analysis Services
A Microsoft online analytical data engine used in decision support and business analytics, providing the analytical data for business reports and client applications such as Power BI, Excel, Reporting Services reports, and other data visualization tools.
1,231 questions
{count} votes

Accepted answer
  1. Michael Taylor 43,971 Reputation points
    2023-01-26T16:42:37.99+00:00

    Deleting rows from a table inside a sproc works the same as you would from writing the raw SQL in SSMS. Can you be more specific about what you're trying to do and why a sproc has any impact on that?

    -- Outside sproc: delete any row where col > 100
    DELETE FROM table1 WHERE col > 100
    
    -- Inside sproc
    CREATE PROCEDURE DeleteFromTable1 AS
    BEGIN  
       DELETE FROM table1 WHERE col > 100
    END
    

    If you want it parameterized then you can do that as well. Just add the parameter to the sproc declaration and use the parameter inside the query just like you would inside any regular SQL script.

    0 comments No comments

0 additional answers

Sort by: Most helpful