Re: Delete cascade?
Posted in 1997
In article <01bc40e2$f9a025a0$666436c2@tyr>, "J'rgen Jamt" <JorgenJ@objektdesign.no> wrote: > > I'm developing a Client/Server application on an Oracle platform. My > application needs to work the same way on different db-platforms. > > I was wondering if THIS platform supports a "ON DELETE CASCADE" - function, > or do I have do delete all the child-records manually? > Sybase doesn't have an explicit "ON DELETE CASCADE" function, but triggers can be used to enforce referential integrity, including cascading deletes. From the 10.x Transact-SQL Users' Guide, chapter 14: What Are Triggers? A trigger is a special kind of stored procedure that goes into effect when you insert, delete, or update data in a specified table. Triggers can help maintain the referential integrity of your data by maintaining consistency among logically related data in different tables. Referential integrity means that primary key values and corresponding foreign key values must match exactly. The main advantage of triggers is that they are automatic : they work no matter what caused the data modification-a clerk's data entry or an application action. A trigger is specific to one or more of the data modification operations, update , insert , or delete . The trigger is executed once per SQL statement. A trigger "fires" only after the data modification statement has completed and SQL Server has checked for any datatype, rule, or integrity constraint violations. The trigger and the statement which "fires" it are treated as a single transaction that can be rolled back from within the trigger. If a severe error is detected, the entire transaction rolls back. In what situations are triggers most useful? w Triggers can "cascade" changes through related tables in the database. For example, a delete trigger on the title_id column of the titles table could cause a corresponding deletion of matching rows in other tables, using the title_id column as a unique key to locating rows in titleauthor , sales , and roysched . w Triggers can disallow, or "roll back", changes that would violate referential integrity, canceling the attempted data modification transaction. Such a trigger might go into effect when you try to insert a foreign key that does not match its primary key. For example, you could create an insert trigger on titleauthor.title_id that rolled back an insert if the new value did not match some value in titles.title_id . w Triggers can enforce restrictions much more complex than those defined with rules. Unlike rules, triggers can reference columns or database objects. For example, a trigger can roll back updates that attempt to increase a book's price by more than 1% of the advance. w Triggers can perform simple "what if" analyses. For example, a trigger can compare the state of a table before and after a data modification, and take actions based on that comparison. --------------------------------------------------------------------- | Bret Halford Imagine my disappointment __| | Sybase Technical Support in learning the true nature __| | 6400 S. Fiddlers Green Circle of rec.humor.oracle... __| | Englewood, CO 80111-4954 USA | ============================================================ -------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet