The issue of a one-one requirement, a new order inserted must be accompanied by a detail row (insert), was raised in the thread: microsoft.public.sqlserver.programming Thursday, June 26, 2008 'update joined tables' http://tinyurl.com/69hh5c While this is a non-trivial exercise in sql it's quite easy in the relational system Dataphor. For example: create session table SOrders { order_nbr:Integer, A:Integer, key{order_nbr} }; create session table SOrderDetails { order_nbr:Integer, sku:Integer, B:Integer, C:String, key{order_nbr,sku}, reference Details_SOrders{ order_nbr } references SOrders { order_nbr } }; This constraint makes a detail row a requirement for a new order. The user defined message will be displayed anytime the constraint is violated. alter table SOrders { create transition constraint MustHaveOrderDetails on insert exists(SOrderDetails where order_nbr=new.order_nbr) tags { DAE.Message = "'A detail row with order#: ' + ToString(new.order_nbr) + ' is required'" } }; Inserting just a new order will violate the constraint: insert row{1 order_nbr, 14 A} into SOrders; Violation of constraint "MustHaveOrderDetails", "A detail row with order#: 1 is required." Inserting data can easily be done via a view. create session view VSOrderDetails SOrders join SOrderDetails;//A natural join on order_nbr. The MustHaveOrderDetails constraint works for the insertion of a single row or a table. insert row{1 order_nbr, 1 sku, 14 A, 5 B, 'Joe' C} into VSOrderDetails; delete SOrders; Insert into the tables thru the view. insert table { row{1 order_nbr, 1 sku, 14 A, 5 B, 'Joe' C}, row{1,2,9,23,'Steve'}, row{2,3,34,2,'Larry'} } into VSOrderDetails; select SOrders; order_nbr A --------- -- 1 14 2 34 select SOrderDetails; order_nbr sku B C --------- --- -- ----- 1 1 5 Joe 1 2 23 Steve 2 3 2 Larry This rather simple example shows off the much higher level of abstraction offered to developers with a relational system like Dataphor over sql. In sql only one table may be updated with a view. In Dataphor there is no concept of updating multiple tables. There is only the idea of updating a view/expression which is a table. It's the system responsibility to resolve a view to its base tables given the constraints in the schema. The user need only realize a table is being used for data modification and it's irrelevant how that table was constructed as well as the number of tables in its definition.
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)
Sunday, July 06, 2008
A one-one requirement constraint
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment