Solved

Lookup Values

Posted on 1998-10-07
1
187 Views
Last Modified: 2010-03-19
Does anyone know of a third-party-product that will allow a MS SQL 7 field to check another table to determine valid values?  This can't be done with a foreign key in my scenario and I don't believe it can be done in SQL.
0
Comment
Question by:scarlett
1 Comment
 
LVL 2

Accepted Solution

by:
formula earned 50 total points
ID: 1090447
Hi Scarlett!

To do what you want to do, you need to write a trigger.
A trigger will valid values in an insert or update from a lookup table.  It will be something like this:

create trigger validate_field
on data_table
for insert,update
as

if (select count(*) from data_table, inserted
       where lookup_table.field!=inserted.field) > 0
 begin
   rollback trans
   raiserror('Error inserting records, Value not valid,16,101)
 end
return
GO

This is not exact, but the general idea.  Let me know if you need any further assistance.

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now