SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,479 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
how can use delete statement for SP
create table table1( col int,col2 varchar(200))
create sp as
(
delete from table1 where condition
)
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.