35.DELETE CASCADE In SQL Server

Published: 11 April 2022
on channel: Vasanth R
3,180
21

In this video, we will see about DELETE CASCADE rules in SQL Server

Script :

CREATE TABLE Countries
(CountryID INT PRIMARY KEY,
CountryName VARCHAR(50),
CountryCode VARCHAR(3))

CREATE TABLE States
(StateID INT PRIMARY KEY,
StateName VARCHAR(50),
StateCode VARCHAR(3),
CountryID INT)


ALTER TABLE [dbo].[States] WITH CHECK ADD CONSTRAINT [FK_States_Countries] FOREIGN KEY([CountryID])
REFERENCES [dbo].[Countries] ([CountryID])
ON DELETE CASCADE
GO

INSERT INTO Countries VALUES (1,'United States','USA')
INSERT INTO Countries VALUES (2,'United Kingdom','UK')
INSERT INTO Countries VALUES (3,'India','IN')

INSERT INTO States VALUES (1,'Texas','TX',1)
INSERT INTO States VALUES (2,'Arizona','AZ',1)
INSERT INTO States VALUES (3,'Edinburg','En',2)
INSERT INTO States VALUES (4,'London','Lo',2)
INSERT INTO States VALUES (5,'Tamil Nadu','TN',3)
INSERT INTO States VALUES (6,'Delhi','DL',3)

Delete from Countries where CountryID=1

select * from Countries
select * from states


On this page of the site you can watch the video online 35.DELETE CASCADE In SQL Server with a duration of hours minute second in good quality, which was uploaded by the user Vasanth R 11 April 2022, share the link with friends and acquaintances, this video has already been watched 3,180 times on youtube and it was liked by 21 viewers. Enjoy your viewing!