DELETE FROM
The below example will explain about the How Delete works when we join two tables and delete the values.
declare @Table table
(sno INT,[Name] varchar(25))
insert @Table
values(1,'Ramesh')
insert @Table
values(2,'Suresh')
select * from @Table
declare @table2 table
(OrderID int,ItemName varchar(30),Sno INT)
INSERT @table2
VALUES(1,'Idli',1)
INSERT @table2
VALUES(2,'Chapathi',4)
SELECT * FROM @table2
DELETE FROM @table2
FROM @table2 as T2 INNER JOIN @Table AS T
ON T2.Sno=T.Sno
SELECT *from @table2
declare @Table table
(sno INT,[Name] varchar(25))
insert @Table
values(1,'Ramesh')
insert @Table
values(2,'Suresh')
select * from @Table
declare @table2 table
(OrderID int,ItemName varchar(30),Sno INT)
INSERT @table2
VALUES(1,'Idli',1)
INSERT @table2
VALUES(2,'Chapathi',4)
SELECT * FROM @table2
DELETE FROM @table2
FROM @table2 as T2 INNER JOIN @Table AS T
ON T2.Sno=T.Sno
SELECT *from @table2
Comments