On 7/13/2012 12:18 AM, Dan Covill wrote: > On 07/12/12 20:13, MB Software Solutions General Account wrote: >> I've seen how to create a rule for data in a column using direct values >> (http://www.databasejournal.com/features/mssql/article.php/3811831/Using-Check-Constraints-to-Validate-Data-in-SQL-Server.htm). >> >> But I want to basically say "Only allow values in this FK field that exist >> as PKs in that other table." >> >> How do I do that? > > If you're doing lots and lots of them, > > SELECT UNIQUE <pk-field> FROM <othertable> INTO ARRAY OKFields > keep the array around, then > IF ASCAN(OKFields, <FKvalue> > 0 > -- it's good -- > > If this is a rare thing, > > SELECT <pk-field> INTO ARRAY Dummy FROM <OTHERTABLE> ; > WHERE <pk-field> = <FKvalue> > if alen(Dummy) > 0 > -- it's good --
Dan, This is not Foxpro. It's SQL Server 2008 R2. -- Mike Babcock, MCP MB Software Solutions, LLC President, Chief Software Architect http://mbsoftwaresolutions.com http://fabmate.com http://twitter.com/mbabcock16 _______________________________________________ Post Messages to: ProFox@leafe.com Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/50001af1.4060...@mbsoftwaresolutions.com ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.