473,406 Members | 2,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Systematically determine DRI problem(s)


Hmm, I'm wondering if some of you have figured out a way to check a
large database's DRI programmatically.
The term, 'a large database' is a loose one, let's just say, at least
over 200 user tables. Yes, DBCC CHECKCONSTRAINTS is handy.
However, it won't be able to tackle some hidden DRI problems. For
instance, here you have two tables, totally fictionary! but possibly
in the
real world, Customer and Account (for demo purpose, I'll name them temp
tables here),
the original designer probably meant to link them via customer_ID,
however, he/she did not do it properly.
-- DDL and DML
-- one day at data life
create table #customer (customer_ID char(12) not null primary key,
first_name varchar(20), last_name varchar(20), sex char(1), state
char(2), ssn char(11),
check(Left(customer_id,2)=state AND Right(customer_id,4)=Right(ssn,4))
)
-- thanks Joe Ceilko for a more meaningufl PK ...
insert into #customer
values('md-1234-1234','Dan','Li','M','VA','567-28-4321')
create table #account (account_id int identity(10000,1) primary key,
account_type varchar(10), amount money, last_update datetime,
first_name varchar(20), last_name varchar(20))

insert into #account (account_type, amount, last_update,
first_name,last_name)
values ('Receivable',3000.0000,getDate(),'Dan','Li')
/* at least two problems here
a) DRI is lost here
b) Instead of 'Dan' and 'Li', one could enter 'NosuchFN' and 'NosuchLN'

-- another day at data life, don't ask me why they do that, I would
likely use ACTIVE flag to keep all data
delete
from #customer
where customer_id = 'md-1234-1234'
-- now, boss ask why do we have this Dan Li in the #account table while
there's no such corresponding record in the #customer table or
who the heck is this Dan Li anyway (give me more info about this guy?)?
Well, if we have only a few or a dozen tables, it won't require tons
of effort to find data problem for the given situation (database),
but again, let's say, this db has over 200 tables, checking them by
hand would seem to be like doing things like Homo Sappiens, I don't
mean
to be lazy, so, how would you systematically at least programmatically
identify the DRI problems?

Many thanks in advance to those clearer heads.
DL

Sep 12 '05 #1
2 1747
NickName (da****@rock.com) writes:
Well, if we have only a few or a dozen tables, it won't require tons
of effort to find data problem for the given situation (database), but
again, let's say, this db has over 200 tables, checking them by hand
would seem to be like doing things like Homo Sappiens, I don't mean to
be lazy, so, how would you systematically at least programmatically
identify the DRI problems?


I'm afraid that the only answer I give, is the one you don't want to
hear: do it right from the beginning.

And if you didn't do it right from the beginning, you have a nightmare
now to sort out. You can of course set up a unique constraint on the
customer name (just temporarily) and then an FK from accounts to see
what happens, but since it's likely to fail, it's not that useful. You
will have to write SELECTs for all relations you want to check.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Sep 12 '05 #2
Erland,

Homer sometimes nodds. We miscommunicated.
"the original designer probably meant to link them via customer_ID"
was meant to say, this or any other such db is inherited from some one
else.

Don

Erland Sommarskog wrote:
NickName (da****@rock.com) writes:
Well, if we have only a few or a dozen tables, it won't require tons
of effort to find data problem for the given situation (database), but
again, let's say, this db has over 200 tables, checking them by hand
would seem to be like doing things like Homo Sappiens, I don't mean to
be lazy, so, how would you systematically at least programmatically
identify the DRI problems?


I'm afraid that the only answer I give, is the one you don't want to
hear: do it right from the beginning.

And if you didn't do it right from the beginning, you have a nightmare
now to sort out. You can of course set up a unique constraint on the
customer name (just temporarily) and then an FK from accounts to see
what happens, but since it's likely to fail, it's not that useful. You
will have to write SELECTs for all relations you want to check.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp


Sep 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number....
5
by: JT | last post by:
how do i determine how many items are in an array? the following code creates an array of values each time a space is found in a name field. the problem is that sometimes names have middle...
5
by: Hennie de Nooijer | last post by:
Hi, This is a diffcult issue to explain. I hope to make my problem clear to you. SITUATION I'm building A SLA Query for a customer. This customer has an awkward way to determine the SLA results...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
3
by: Web Webon | last post by:
Hi everybody! I wonder if this is possible? I need to determine if a client is using "windows classic folders" or anything else. If I instantiate a Shell ActiveX object is there a way of...
2
by: Chris Carter | last post by:
We have a site, for reference I'll call this MainSite, that has certain pages actually hosted on another site, I'll call this ChildSite. In MainSite when you click on a certain link, it loads a...
16
by: Jm | last post by:
Hi All Is it possible to determine who is logged onto a machine from inside a service using code in vb.net ? I have found some code that seems to work under vb6, but doesnt under .NET ? Any help...
25
by: lovecreatesbeauty | last post by:
Hello experts, I write a function named palindrome to determine if a character string is palindromic, and test it with some example strings. Is it suitable to add it to a company/project library...
7
by: semedao | last post by:
Hi all, I view many posts about this issue , the connected property does not tell us the current status of the socket. based on couple of suggestions of msdn , and some article here , I try to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.