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

Comments

Popular posts from this blog

System.Data.SqlClient.SqlException (0x80131904): Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out

Pre login Handshake or Connection Timeout Period

Transparent Data Encryption(TDE) with Master Key and Certificate in SQL Server