|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
how to set up a 'cascading delte' in mssqlI'm used to working with Access but have moved to MSSQL 2005.
I have these tables: tblCustomer: customerID (auto), name (nvarchar,50) tblOrders: orderID (auto), customerID (int) I use SSMSE. How can I set it up so that the related records in tblOrders are deleted if I delete a customer. Thanks. Jesper Jesper F (askfortheem***@ask.com) writes:
> I'm used to working with Access but have moved to MSSQL 2005. ALTER TABLE tblOrders ADD > I have these tables: > > tblCustomer: customerID (auto), name (nvarchar,50) > tblOrders: orderID (auto), customerID (int) > > I use SSMSE. How can I set it up so that the related records in tblOrders > are deleted if I delete a customer. CONSTRAINT fk_order_customers FOREIGN KEY (customerID) REFERENCES tblCustomers (customerID) ON CASCADE DELETE Although, I must say that from my corners, this looks like a funny business rule... -- Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se Books Online for SQL Server 2005 at http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx Books Online for SQL Server 2000 at http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx > ALTER TABLE tblOrders ADD Those were imaginary tables, but thanks for pointing me in the right > CONSTRAINT fk_order_customers FOREIGN KEY (customerID) > REFERENCES tblCustomers (customerID) ON CASCADE DELETE > > Although, I must say that from my corners, this looks like a funny > business rule... direction. Jesper |
|||||||||||||||||||||||