İlişkili Tablolardan Kayıt Silme

İpucu : Northwind veri tabanında bir müşteriyi silince (cascade şekilde) siparişlerinin ve sipariş detaylarının silinmesi.

create proc MusteriSil

(
@id nchar(5)
)
as
exec   MusterininSiparisleriniSil   @id

Delete from Customers Where CustomerID=@id
——————————————————————-

create proc MusterininSiparisleriniSil
(
@id nchar(5)
)
as

Delete   [Order Details]  from  [Order Details]   inner join   Orders
on   Orders.OrderID  =  [Order Details].OrderID
Where   Orders.CustomerID  =  @id

Delete   from   Orders   Where   Orders.CustomerID = @id

———————————————

create proc SiparisDetaylariniSil
(
@OrderID int
)
as
Delete from [Order Details] where OrderID=@OrderID
———————————————————-

exec   MusteriSil   ‘ANTON’

Reklamlar