Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Cascade

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-03-29 : 09:35:12
ky writes "How to use cascade to hlep in updating and deleting the child tables when changes are made at parent table ?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-03-29 : 10:55:00
In SQL Server 2000, you can declare foreign keys to cascade update and delete actions:

CREATE TABLE Customers (Account int NOT NULL PRIMARY KEY,
Name varchar(50) NOT NULL)
CREATE TABLE Orders (OrderID int,
Account int FOREIGN KEY REFERENCES Customers(Account) ON DELETE CASCADE ON UPDATE CASCADE)


In SQL Server 7.0 and earlier, you must write triggers to handle the cascade update and delete. If you do, you must disable any declared foreign keys between the tables, because a foreign key violation will not fire the trigger.

Books Online has details on foreign keys and triggers.

Go to Top of Page
   

- Advertisement -