We know what Cascade is in SQL Server.
To explain this I will create two simple tables, employee and empsalary.
Table 1
CREATE TABLE employee (
id int not null ,
name varchar(30),
PRIMARY KEY (id)
)
insert into employee values(1,'RAVI')
insert into employee values(2,'ISHA')
insert into employee values(3,'SANTOSH')
insert into employee values(4,'PRAGYA')
Table 2
CREATE TABLE empsalary (
id int not null,
salary money
)
ALTER TABLE empsalary
alter CONSTRAINT FK1
FOREIGN KEY (id) REFERENCES employee(id)
insert into empsalary values(1,20000)
insert into empsalary values(2,1000)
insert into empsalary values(3,50000)
insert into empsalary values(4,70000)
The first table contains records of empid and empname. Depending on empid I will insert their salary into the second table.
I created a FOREIGN KEY on id in the second table. In other words, here only those records will be entered that exist in the first table with the same id.
Now we have two tables with references and some records. If the user wants to delete or update some records from the first table (employee) that references records that exist in the second table then SQL returns the following error.
Query
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.


SubashPosted Jul 21, 2016, 5:05 AM
Nice
sijo paulPosted Oct 10, 2014, 1:55 AM
good one
Akash BhimaniPosted Nov 17, 2013, 10:58 AM
great contribution....... :)
Ravi ShekharPosted Nov 17, 2013, 9:42 AM
Thankyou Anil Sir ..:)
Anil KumarPosted Nov 17, 2013, 8:57 AM
Keep it up ! nice to see you authoring articles :)