Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / General DB Topics / DB Theory / April 2004

Tip: Looking for answers? Try searching our database.

Should an application ever be allowed to change a schema?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Karen Sundquist - 17 Apr 2004 12:16 GMT
Hi there

Imagine a database that is only accessed by a server application. This
application provides the ability for admin users to create templates
for forms. When a template is created, other users of the application
can then submit instances of a form, which is then stored in the
database.

The form templates are used by the application to generate GUI front
ends to enter data. The form data collected is transmitted to external
systems for processing.

This must be a common problem so how would any of you model this in a
relational database?

There are two approaches that come to my mind:
Solution 1. Header table and Value Pairs

A table stores the header info for each form template.
e.g.
CREATE TABLE FORM(
FormID NUMBER PRIMARY KEY,
FormName VARCHAR2(40) NOT NULL,
CreatedBy VARCHAR2(40) NOT NULL,
CreateDate DATE NOT NULL)

Another table is used to store the field names

CREATE TABLE FORMFIELD(
FormFieldID NUMBER PRIMARY KEY,
FormID NUMBER CONSTRAINT formfield_fk REFERENCES FORM(FormID),
FieldName VARCHAR2(40) NOT NULL,
FieldType VARCHAR2(40) NOT NULL,
FieldLength VARCHAR2(40) NOT NULL,
IsRequired NUMBER NOT NULL,
CanBeNULL NUMBER NOT NULL)

Then, instance tables are used to store the instances of forms
submitted by users.

CREATE TABLE FORMINSTANCE(
FormInstanceID Number PRIMARY KEY,
FormID NUMBER CONSTRAINT forminstance_fk REFERENCES FORM(FormID),
CreatedBy VARCHAR2(40) NOT NULL,
CreateDate DATE NOT NULL)

CREATE TABLE FORMFIELDINSTANCE(
FormFieldInstanceID NUMBER PRIMARY KEY,
FormInstanceID NUMBER CONSTRAINT formfieldinstance_fk REFERENCES
FORMINSTANCE(FormInstanceID),
FormFieldID NUMBER CONSTRAINT formfieldinstance2_fk REFERENCES
FORMFIELD(FormFieldID),
FieldData VARHCHAR2(100) NULL)

The FieldData field is used to store actual data captured when users
fill in a form. This data then has to be CAST to the appropriate type.

Now this looks like a workable solution to me but I don't like the way
data has to be stored as a VARCHAR and CAST back to something else.

Solution 2. Header table and Dynamic Table Creation

As before,
A table stores the header info for each form template.
e.g.
CREATE TABLE FORM(
FormID NUMBER PRIMARY KEY,
FormName VARCHAR2(40) NOT NULL,
CreatedBy VARCHAR2(40) NOT NULL,
CreateDate DATE NOT NULL)

However this time, the application creates a new table for each form
template which is then used to store the form data
e.g.
CREATE TABLE AUTOAPPLICATIONFORM1(
FormInstanceID NUMBER PRIMARY KEY,
FormID NUMBER CONSTRAINT autoapplicationform1_fk REFERENCES
FORM(FormID),
ApplicantFirstName VARCHAR2(40),
ApplicantLastName VARCHAR2(40),
ApplicationDate DATE,
etc...

In this solution we could end up with many tables, yet we are using
the storage facilities of the RDBMS better. Also we are allowing the
schema to dynamically change.

From a practical and theoretical point of view, which of these
approaches is better?
Have any of you seen this problem before?
Is there another way I haven't thought of?

Thanks!

Karen
mAsterdam - 17 Apr 2004 13:33 GMT
> Imagine a database that is only accessed by a server application.

(Sorry for being slightly off-topic.
I am trying to initiate a c.d.theory glossary.)

This effectively reduces the meaning of the word 'database' to
'deluxe filesystem'. No problem, many use the word in that sense.
The implication it is that part of the server application may be
busy taking care of contraints which would have to be guarded by the
dbms if there would be other applications. Typically, developers
*will* implement some of the more complicated contraints in
the server application. This severely limits the chance of the
data ever being shared. 'Import' and 'export' facilities
become crucial to the success of the application.

> This
> application provides the ability for admin users to create templates
[quoted text clipped - 11 lines]
> There are two approaches that come to my mind:
> Solution 1. Header table and Value Pairs

[snip casting solution]

To me it looks as if you are trying to implement
a generic, table driven data-capture gui in front
of another, more specific datacollection, so the
casting doesn't really surprise me.

> Solution 2. Header table and Dynamic Table Creation

[snip dynamic schema solution]

> In this solution we could end up with many tables, yet we are using
> the storage facilities of the RDBMS better. Also we are allowing the
> schema to dynamically change.
>
> From a practical and theoretical point of view, which of these
> approaches is better?

Practical: I've seen both. The dynamic schema approach seems to
fit big workflow applications. I did not see recent examples of
the casting approach for big applications, so maybe it doesn't
scale as well. The dynamic schema approach requires thorough
knowledge of the specific dbms.

Theoretical: I prefer programming languages for programming
instead of tables.

> ... Is there another way I haven't thought of?

I don't know.

Just my 2 Eurocents.
Laconic2 - 17 Apr 2004 15:15 GMT
> The implication it is that part of the server application may be
> busy taking care of contraints which would have to be guarded by the
[quoted text clipped - 3 lines]
> data ever being shared. 'Import' and 'export' facilities
> become crucial to the success of the application.

Agreed.  Let me add my two US cents.

Why does the above severely limit the chance of the data ever being shared?

I think it's because constraints that are buried deep in the code are often
separated from the data thus produced.  Thus,  if the writers of some data
adhere to a contstraint that is unkown to the readers,  then some
information inherent in the data has been lost to the readers.

More commonly,  if the readers infer that the data adheres to a constraint,
when no such constraint exists for the writers,  then the information the
readers derive from that constraint has the quality of "lore"  about it.
That is,  the readers attribute inferences to the data that the data does
not, in fact, convey.

In practice this situation can cause things to run very smoothly,  until the
day comes when some data that violates the constraint is written to the data
base.  Then all hell breaks loose.
Karen Sundquist - 17 Apr 2004 19:34 GMT
> > Imagine a database that is only accessed by a server application.
>
[quoted text clipped - 10 lines]
> data ever being shared. 'Import' and 'export' facilities
> become crucial to the success of the application.
I don't understand your deduction that a database accessed only by
server applications is no longer a database or that constraints cannot
be included is such a database. Is it because, the actual users are
hidden from the database, so user level privileges must be looked
after by the application?

As you know, many databases these days are accessed directly only by
the superuser and by a number of middleware server applications that
marshal end user queries. Data is shared by these separate
applications. Critical constraints are included in the database that
are common to all users of the data. The middleware applications may
impose their own local constraints which are not critical to the
integrity of the data.

Karen
mAsterdam - 17 Apr 2004 20:17 GMT
> mAsterdam wrote:
>>>Imagine a database that is only accessed by a server application.
[quoted text clipped - 13 lines]
> hidden from the database, so user level privileges must be looked
> after by the application?

No, not at all.

In writing there is only a small
difference between the singular 'a server
application' from your first post, and the plural
'server applications' from your second post.

However, to your architecture it matters a lot.

In the singular case you can protect your data wherever
you see fit. In the plural case you had better put all
constraints which protect your data in the database.
A few weeks ago there
was a thread about the redundancy in the constraint
specification caused by this.

> As you know, many databases these days are accessed directly only by
> the superuser and by a number of middleware server applications that
[quoted text clipped - 3 lines]
> impose their own local constraints which are not critical to the
> integrity of the data.

Who is responsible for the constraints imposed by the middleware?
Which data do these constraints protect?
Why would middleware protect data?
My take is:
Use the middleware to store and forward messages.
That is what it is designed for.
Timothy J. Bruce - 18 Apr 2004 01:12 GMT
Karen:

>               Critical constraints are included in the database that
> are common to all users of the data. The middleware applications may
> impose their own local constraints which are not critical to the
> integrity of the data.

*ALL* constraints are critical to and for integrity, and therefore
belong in the DBMS, as declaritive constraints when possible.  I am
aware that many products offered today may not offer the level of
control and logic I insist apon, thus making the scenario you
described above more common than most suspect.

Just because I should doesn't mean I can,
Timothy J. Bruce
uniblab@hotmail.com
</RANT>
Anthony W. Youngman - 24 Apr 2004 15:10 GMT
>> Imagine a database that is only accessed by a server application.
>
[quoted text clipped - 3 lines]
>This effectively reduces the meaning of the word 'database' to
>'deluxe filesystem'. No problem, many use the word in that sense.

Doesn't the planned implementation of Longhorn use SQL-Server as its
filesystem?

What about Native Pick? Or OS/400?

In some cases, the "deluxe file system" IS what you would call a
database, I suspect. In others (Longhorn?) I suspect the use of a
database is a gross abuse of the concept of a filesystem :-)

Shades of grey.

Cheers,
Wol
Signature

Anthony W. Youngman - wol at thewolery dot demon dot co dot uk
HEX wondered how much he should tell the Wizards. He felt it would not be a
good idea to burden them with too much input. Hex always thought of his reports
as Lies-to-People.
The Science of Discworld : (c) Terry Pratchett 1999

mAsterdam - 24 Apr 2004 16:27 GMT
> mAsterdam writes
>>
[quoted text clipped - 5 lines]
> Doesn't the planned implementation of Longhorn use SQL-Server as its
> filesystem?

Ah, the sequel to the OS that has a
web-browser and a media-player
as essential, impossible-to-remove parts.

> What about Native Pick? Or OS/400?

They both use technology that originated from databases
at an unusal level.
I haven't ever worked on AS/400, but what I hear from people
who do is that they like it very much for database applications.
Same goes for Pick.

> In some cases, the "deluxe file system" IS what you would call a
> database, I suspect. In others (Longhorn?) I suspect the use of a
> database is a gross abuse of the concept of a filesystem :-)

:-)

> Shades of grey.

Some demarcation lines do get blurred.

"The filesystem is the database"
"The network is the computer"
"The media is the message"
"L’État, c’est moi"
Laconic2 - 17 Apr 2004 23:36 GMT
Why do you want a database?
Karen Sundquist - 20 Apr 2004 09:37 GMT
> Why do you want a database?
We would make more progress with this discussion if we had common
definitions for terms such as 'database' and 'constraint'.

Good luck with the glossary.

Karen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.