Re: Subquerie in CHECK Constrain

From: Tibor Karaszi (tibor_please.no.email_karaszi_at_hotmail.nomail.com)
Date: 10/20/04


Date: Wed, 20 Oct 2004 07:43:20 +0200


> I'm so embaressed. It 's a foreign key. BUAAAAAA. :-(

Don't be. These things happens to all of us from time to time. :-)

I recall once retrieving a record set in VB, looping it and for each row, executing another
statement correlating a rows from the first recordset in the other query, and so on, 4 levels deep.
Lunch. During lunch I realized that I was mimicking a JOIN inside VB...

-- 
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Nuno Silva" <NunoSilva@discussions.microsoft.com> wrote in message 
news:3C5AFC5C-29C4-4F27-8DD7-CB56B53B5A88@microsoft.com...
> Kalen, Tibor, Gert and Robert,
>
> I'm so embaressed. It 's a foreign key. BUAAAAAA. :-(
>
> This tables that i?m designing are to receive data from XML files and they
> gave me the .dtd of the XMl, and I was trying to design the tables with the
> exact rules of the .dtd files.
> Thanks once more, for your time.
>
> Nuno
>
> "Kalen Delaney" wrote:
>
>> Yep, I answered the specific question without thinking about exactly what
>> was being done.
>> Even the column names make it seem like we might be dealing with a foreign
>> key.
>>
>> Thanks, Tibor!
>>
>> -- 
>> HTH
>> ----------------
>> Kalen Delaney
>> SQL Server MVP
>> www.SolidQualityLearning.com
>>
>>
>> "Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in
>> message news:eGZJGLgtEHA.4044@TK2MSFTNGP09.phx.gbl...
>> > Return a scalar (0 or 1, for example).
>> >
>> > And pass a comma separated value in, which you in the function parse and
>> > build a temp table with which you can drive the IN with a subquery. Some
>> > alternatives found here: http://www.sommarskog.se/arrays-in-sql.html
>> >
>> > OTOH, this smells like you should have an ordinary foreign key instead?
>> >
>> > -- 
>> > Tibor Karaszi, SQL Server MVP
>> > http://www.karaszi.com/sqlserver/default.asp
>> > http://www.solidqualitylearning.com/
>> >
>> >
>> > "Nuno Silva" <NunoSilva@discussions.microsoft.com> wrote in message
>> > news:8A7641D0-C343-4388-A645-6BA8986C658B@microsoft.com...
>> >> OK,
>> >> But what should I return? Table? Scalar? If I right understand, I can
>> >> only
>> >> use UDF that return scalar values to check constrains and the two columns
>> >> that I'm trying to compare are char type, how I should I do it?
>> >>
>> >> Thanks
>> >>
>> >> "Kalen Delaney" wrote:
>> >>
>> >>> Hi Nuno
>> >>>
>> >>> You can't use a subquery, but you can use a User Defined Function in SQL
>> >>> Server 2000.
>> >>> The UDF can reference another table.
>> >>>
>> >>> -- 
>> >>> HTH
>> >>> ----------------
>> >>> Kalen Delaney
>> >>> SQL Server MVP
>> >>> www.SolidQualityLearning.com
>> >>>
>> >>>
>> >>> "Nuno Silva" <NunoSilva@discussions.microsoft.com> wrote in message
>> >>> news:2B03F7F1-6DEF-43B8-848B-2E0F89E494FA@microsoft.com...
>> >>> > Hi,
>> >>> > I'm trying to create a check constrain that goes check in a table if
>> >>> > the
>> >>> > value exists.
>> >>> > Something like:
>> >>> >
>> >>> > Natur_Jur IN ( SELECT ID_Natur_Jur FROM tblXML_V_NaturezaJuridica )
>> >>> >
>> >>> > When I try to save the table I get one error message that I cannot
>> >>> > have
>> >>> > subqueries in check constrain, what I think that is very strange that
>> >>> > SQL
>> >>> > Server doesn't have this feature.
>> >>> >
>> >>> > I'm doing something wrong or is it true the message that I get?
>> >>> > Thanks in advanced,
>> >>> > Nuno Silva
>> >>> >
>> >>>
>> >>>
>> >>>
>> >
>> >
>>
>>
>> 


Relevant Pages

  • Re: Errors in Event Log
    ... Tibor Karaszi, SQL Server MVP ... "Kalen Delaney" wrote in message ... > "Peter Blackwell" wrote in message ... >>> Tibor Karaszi, SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: SQL 6.5 DB without a Master.dat
    ... Tibor Karaszi, SQL Server MVP ... "Kalen Delaney" wrote in message ... >> It is DISK REINIT, ... >> Tibor Karaszi, SQL Server MVP ...
    (microsoft.public.sqlserver.server)
  • Re: Question on Cursor
    ... Kalen Delaney ... Tibor Karaszi, SQL Server MVP ... work in dialect, but it makes you look like a hillbilly. ...
    (microsoft.public.sqlserver.programming)
  • Re: date time (today)
    ... You find such example (with variations) in this article: ... Tibor Karaszi, SQL Server MVP ... > what's the best way to select return a record set of all rows that have been ...
    (microsoft.public.sqlserver.programming)
  • Re: 64bit insert delays
    ... Tibor Karaszi, SQL Server MVP ... > we/users can query when mails were processed by the antispam system, ... this sounds like you are selecting from some other table than the one inserting into and you ... >> Tibor Karaszi, SQL Server MVP ...
    (microsoft.public.sqlserver.programming)

Loading