Unix Technical Forum

Check Data Before Update

This is a discussion on Check Data Before Update within the SQL Server forums, part of the Microsoft SQL Server category; --> Hello Everybody! I have a POLINE table on a SQL Server 2000 DB. Before I update the record I ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 06:11 PM
Martin
 
Posts: n/a
Default Check Data Before Update

Hello Everybody!

I have a POLINE table on a SQL Server 2000 DB. Before I update the
record I need to check that either field, STORELOC or WONUM has data
on it. If both fields are NULL I would like to send a message letting
the user know that either fields needs data before they can save the
record. If any of the fields have data then, it is OK to save the
record.

Could you please let me know how to accomplish this? An example will
be really helpful, I can do this in Access but I do not know how to do
it in SQLServer. I was thinking using trigger but there are not really
good examples.

Thanks in Advance!

Martin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 06:12 PM
Erland Sommarskog
 
Posts: n/a
Default Re: Check Data Before Update

[posted and mailed, please reply in news]

Martin (martin.wunder@wsidc.com) writes:
> I have a POLINE table on a SQL Server 2000 DB. Before I update the
> record I need to check that either field, STORELOC or WONUM has data
> on it. If both fields are NULL I would like to send a message letting
> the user know that either fields needs data before they can save the
> record. If any of the fields have data then, it is OK to save the
> record.
>
> Could you please let me know how to accomplish this? An example will
> be really helpful, I can do this in Access but I do not know how to do
> it in SQLServer. I was thinking using trigger but there are not really
> good examples.


The answer is that you don't do this in SQL Server.

No, get me right. You can certainly have a check for this in SQL Server:

create table POLINE (...
STORELOC some_type not null,
WONUM other_type not null,
...
constraint POLINE_CHK_STORELOC_WONUM
check (STORELOC is not null or WONUM is not
null)

This table constraint will cause SQL Server to flatly accept any rows
where both columns are NULL. If exactly one should be non-NULL the
check should read:

STORELOCK is not null and WONUM is null or
STORELOCK is null and WONUM is not null

However, this does not really meet your requirements, because the
message will not be useful to the user. To this end, you need to
do the check in the client.

There is an important difference between Access and SQL Server. Access
is both database and GUI in one, but SQL Server is only the server
side, and requires a client on the other end. (Which could be Access.)

Still constraints like these are very useful, because they can cover
up for tests that the GUI programmer failed to include, and protect
the integirty of the data.


--
Erland Sommarskog, SQL Server MVP, sommar@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:46 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com