At 02:51 PM 2/13/2004, Jeff Varszegi wrote
>J. Merrill wrote (in part):
>
>> One technique I've used successfully, but have not seen discussed here, is that of 
>> having
>> application code that generates the code for stored procedures, triggers, and 
>> views.  Sometimes,
>> that code will be "constant" -- but much of the time, it will vary based on column 
>> datatypes.
>...
>> I could give some real-world examples of where this has seemed to be the only 
>> reasonable
>> solution, if anyone cares.
>
>Shoot!  This email stuff is still tax-free.  :O)  I, at least, am very interested.

The best examples I have involve design of a database to represent hospital patient 
records.  There are a number of things that are different about different client 
installations -- for example, there's a big infrastructure for Canadian sites that's 
relevant to the Canadian govt-run healthcare system, in order to provide govt-required 
reports.  Some views are defined that include constant NULL  values if it's a U.S. 
site, and the relevant columns if it's Canadian.  There's a view that returns 
information about all the different "roles" a physician can play; based on which 
sub-systems are installed at the site, some of them are N/A.  Some sites are part of a 
multi-site organization; those sites have an "enterprise patient identifier" value in 
an EPI table.  When building a view that "flattens" the patient / visit info (for use 
mostly by Crystal Reports), there's no reason to join to the EPI table if it's the 
client's not using EPI (and the EPI column in the view is a constant NULL in that case 
-- again, for the report-writers).

I also built an auditing mechanism based on triggers.  The users can choose (for any 
table) which columns are reported during each of insert / update / delete.  During 
insert and delete, any non-null value in a reported column results in a record in the 
audit table; during update, any changed value produces an audit record.  The code to 
test if (e.g.) a nullable varchar has changed is different from the code that tests a 
NOT NULL integer.  The mechanism also does callbacks into the application (so the same 
tool works for multiple applications) to get info to permit us to record -- back in 
the hospital system -- values for patient_id and/or visit_id even when the table being 
audited is a great-grandchild of one of those tables.  (Given a "table tree" there's a 
tool that produces the join needed to get from any table to any other [connected] 
table.)

Metadata lets you have one infrastructure that supports many rather different 
applications.

>[snip]
>I think that all of these issues also have different answers depending on who's using 
>the
>database.  For instance, sometimes a DBA <i>has</i> to keep reins on schema changes, 
>because a
>database is used directly by other applications.  In situations where a database is 
>created
>specifically for one application, I'd see my way clear to a much more loosey-goosey 
>approach, even
>leaving out all constraints (even {gasp} foreign key constraints) in the interests of 
>speed, if I
>had complete faith in the application code.  Speed is almost always one of my top 
>concerns; I'm
>just a freak like that.
>
>Jeff

I'm not sure I agree with you here.  What kind of changes do you need to "rein in"?  
Adding more columns (either nullable, or with a default) does not affect properly 
written SQL -- an app that uses SELECT * or has INSERT statements without a column 
list should not have been deployed, and they deserve to fail.  Only adding new tables, 
and making FK columns pointing to those tables NOT NULL, will cause a failure in 
un-modified code.  Even if such columns are NOT NULL, if they have a default value -- 
e.g. 0 -- that matches a "default record" in the new table (e.g. one with "No such 
animal" in its description field), that won't break existing code.

The infrastructure allows clients to add columns to any table.  Nothing happens unless 
they put one of those columns on an input form; the GUI for the column is based on the 
info the user entered into what the users know as "the field farm."  (We all have 
something like that, right?)

"Speed is almost always one of my top concerns" seems an odd statement when a 
medium-range server you can get today is 10-20 times faster (particularly if you more 
RAM in it than the size of your database) than the fastest you could get 4 years ago.  
"Premature optimization is the root of all evil" is a statement with which I agree.  
(People much smarter than I said it first.)

More about this should probably be off-line.

J. Merrill / Analytical Software Corp

===================================
This list is hosted by DevelopMentor�  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to