This example is based on the thread: microsoft.public.sqlserver.programming Jan 21, 2009 'JET Referential Integrity superior than SQL' http://tinyurl.com/d58ubl Sql Server can't deal with more than 1 cascade to a table. Some nonsense about cycles. I guess if two paths are involved they call it a bi-cycle ☺ It simply is a poor system for relationally modeling a business problem. Simply replace it with Dataphor and use sql server to store the data. Sql server doesn't screw up data storage ☺ Here's how simple this example is with Dataphor (and sql server as the backend). The tables will be persisted in sql server but Dataphor will (mercifully) perform all the integrity checks. create table users { id:Integer, username:String tags{Storage.Length='50'}, key{id}, key{username} }; create table table2 { id:Integer, user1:String tags{Storage.Length='50'}, user2:String tags{Storage.Length='50'}, user3:String tags{Storage.Length='50'} , key{id}, reference user1username {user1} references users {username} update cascade delete cascade, reference user2username {user2} references users {username} update cascade delete cascade, reference user3username {user3} references users {username} update cascade delete cascade }; users:= table{ row{1 id,'john' username}, row{2,'steve'}, row{3,'judy'}, row{4,'larry'}, row{5,'bill'}, row{6,'rita'}}; This row would violate the user3username constraint. insert row{12 id,'john' user1,'rita' user2, 'stan' user3} into table2; //Error: The table users does not have a row with username "stan". table2:=table{ row{10 id,'john' user1,'steve' user2, 'judy' user3}, row{11,'larry','rita', 'bill'}, row{13,'larry','steve', 'steve'}, row{14,'judy','steve', 'john'}, row{15,'bill','judy','rita'}, row{16,'steve','bill', 'judy'}, row{17,'john','bill','john'}}; select table2; id user1 user2 user3 -- ----- ----- ----- 10 john steve judy 11 larry rita bill 13 larry steve steve 14 judy steve john 15 bill judy rita 16 steve bill judy 17 john bill john Check the cascading updates. In table table2 all entries of 'john' are replaced with 'paul'. update users set {username:='paul'} where username='john'; select table2; id user1 user2 user3 -- ----- ----- ----- 10 paul steve judy 11 larry rita bill 13 larry steve steve 14 judy steve paul 15 bill judy rita 16 steve bill judy 17 paul bill paul Check the cascading deletes. Any row in table2 with an entry of 'steve' is deleted. delete users where username='steve'; select table2; id user1 user2 user3 -- ----- ----- ----- 11 larry rita bill 15 bill judy rita 17 paul bill paul Dataphor is open source, get a copy here: http://databaseconsultinggroup.com/downloads/
Dataphor SQL RAC (Relational Application Companion)
A site of hope for those looking for a true relational database system
- a one-one requirement constraint with dataphor (1)
- anatomy of sql server part I - what is a stored procedure (1)
- anatomy of sql server part II - the unit test as part of the database (1)
- anatomy of sql server part III - what does deferred name resolution really mean (1)
- censoring sql posts (1)
- creating an opposite constraint in dataphor (1)
- dataphor (2)
- Dataphor (7)
- dataphor # 13 a table as a parameter (1)
- dataphor - download and start working with it (1)
- dataphor - fixed sized word segments (1)
- dataphor # 10 sql mythology (1)
- dataphor # 11 string differences (1)
- dataphor # 12 trimming a string (1)
- dataphor # 14 sql the meaning of Update..From (1)
- dataphor # 15 views with substance (1)
- dataphor # 16 inclusive vs exclusive solutions (1)
- dataphor # 17 a visual look at ranking queries (1)
- dataphor # 18 data scrubbing using lists (1)
- dataphor # 19 create intervals over strings (1)
- dataphor # 20 browsing an sql window (1)
- dataphor # 21 an example of relational division (1)
- dataphor # 22 reusable procedures (1)
- dataphor # 23 repley to Michel (1)
- dataphor # 24 basics of the table type (1)
- dataphor # 25 extending the dense rank function (1)
- dataphor # 26 query a hierarchy with explode (1)
- dataphor # 27 combine strings with Split and Concat (1)
- dataphor # 28 constants and variables or sql and D4 (1)
- dataphor # 29 another example of relational division (1)
- dataphor #1 introduction (1)
- dataphor #2 splitting strings (1)
- dataphor #3 string concatenation (1)
- dataphor #4 comment (1)
- dataphor #5 comment (1)
- dataphor #6 formal definition (1)
- dataphor #7 sql: table this (1)
- dataphor #8 list to table (1)
- dataphor #9 table constraints (1)
- dataphor creating lists in a query (1)
- extracting numbers from a string with dataphor (1)
- jeff modens dynamic crosstabs for sql server (1)
- linq to sql the what and why (1)
- linq to sql as a window of opportunity to sql users (1)
- linq to sql should be important to sql users (1)
- linq to sql vs. older 4GL attempts (1)
- listing missing table item (1)
- Multiple cascade paths to the same table (1)
- RAC (4)
- RAC #1 comment (1)
- RAC #2 example (1)
- RAC #3 finding the Nth number in a string (1)
- RAC #4 Sql Server 2005 ranking functions vs. Rac ranking (1)
- sorting a delimited string by its numerical string parts (1)
- sql an example of extreme implicit conversions (1)
- sql can't handle complicated cascading updates (1)
- sql CTE should be a variable not a value (1)
- sql dense rank for identifying consecutive runs (1)
- sql is there really a table variable (1)
- sql ranking functions explained by relational types (1)
- sql server triggers are best set based (1)
- sql the idea of using substring to simulate lists (1)
- sql the undefined trigger in Sql Server (1)
- sql vs relational on tables (1)
- sql what the sql CTE covers up (1)
- types and procedures (1)
Thursday, January 22, 2009
Multiple cascade paths to the same table
Subscribe to:
Posts (Atom)