Delete in a stored procedure : Delete Data « Transact SQL « SQL Server / T-SQL






Delete in a stored procedure

 


5> CREATE TABLE OrderDetails(
6> orderID       int NOT NULL,
7> PartID   int NOT NULL,
8> Quantity int NOT NULL);
9> GO
1>
2>
3>
4> INSERT INTO OrderDetails VALUES(10001, 11, 12)
5> INSERT INTO OrderDetails VALUES(10001, 42, 10)
6> INSERT INTO OrderDetails VALUES(10001, 72, 5)
7> INSERT INTO OrderDetails VALUES(10002, 14, 9)
8> INSERT INTO OrderDetails VALUES(10002, 51, 40)
9> INSERT INTO OrderDetails VALUES(10003, 41, 10)
10> INSERT INTO OrderDetails VALUES(10003, 61, 35)
11> INSERT INTO OrderDetails VALUES(10003, 65, 15)
12>
13> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)
1>
2> CREATE PROC dbo.usp_OrderDetailsDelete
3>   @orderid int,
4>   @partid  int
5> AS
6> DELETE FROM OrderDetails
7> WHERE
8>     orderid = @orderid
9>   AND
10>     partid = @partid
11> GO
1>
2>
3> drop table OrderDetails;
4> GO

 








Related examples in the same category