Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.sqlserver.programming > #31269

Re: Unique Constraint Based on Dual GUID

X-Received by 10.182.38.164 with SMTP id h4mr27175179obk.40.1439322404483; Tue, 11 Aug 2015 12:46:44 -0700 (PDT)
X-Received by 10.140.105.102 with SMTP id b93mr275752qgf.26.1439322404360; Tue, 11 Aug 2015 12:46:44 -0700 (PDT)
Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!se8no2125154igc.0!news-out.google.com!b31ni6136qge.0!nntp.google.com!69no5083264qgl.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups microsoft.public.sqlserver.programming
Date Tue, 11 Aug 2015 12:46:44 -0700 (PDT)
In-Reply-To <mqbsbp$9va$1@dont-email.me>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=173.61.135.70; posting-account=SOVadwoAAAB3h7W1MLW9kMYtEc2JW2L8
NNTP-Posting-Host 173.61.135.70
References <mqbsbp$9va$1@dont-email.me>
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <6516db0e-cb01-4b62-99fa-c304a5ee9787@googlegroups.com> (permalink)
Subject Re: Unique Constraint Based on Dual GUID
From rpresser <rpresser@gmail.com>
Injection-Date Tue, 11 Aug 2015 19:46:44 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com microsoft.public.sqlserver.programming:31269

Show key headers only | View raw


On Tuesday, August 11, 2015 at 12:08:02 AM UTC-4, Michael Cole wrote:
> Putting a constrain on these two fields will limit it to only one 
> combination of the two fields, i.e., a link of A to B, but I also need 
> to ensure that the link is not duplicated as B to A - the link is 
> non-directional.
> 
> My idea was to include a calculated field of the two GUIDs XORed 
> together, and place a constraint on this calculated field.  Can anyone 
> see any issues with this idea?

Rather than an XOR, which as Erland points out could cause false positives, why not use a calculated field that appends the two GUIDs together with the one that is "less" coming first?

CREATE FUNCTION OneWayOnly
    (
      @guid1 UNIQUEIDENTIFIER ,
      @guid2 UNIQUEIDENTIFIER
    )
RETURNS VARCHAR(72)
AS
    BEGIN
        DECLARE @g1 VARCHAR(36) ,
            @g2 VARCHAR(36) ,
            @result VARCHAR(72);
        SET @g1 = CONVERT(VARCHAR(36), @guid1);
        SET @g2 = CONVERT(VARCHAR(36), @guid2);
        IF @g1 < @g2
            SET @result = @g1 + @g2;
        ELSE
            SET @result = @g2 + @g1;
        RETURN @result;
    END;

Back to microsoft.public.sqlserver.programming | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Unique Constraint Based on Dual GUID Michael Cole <invalid@invalid.com> - 2015-08-11 14:07 +1000
  Re: Unique Constraint Based on Dual GUID Erland Sommarskog <esquel@sommarskog.se> - 2015-08-11 21:35 +0200
  Re: Unique Constraint Based on Dual GUID rpresser <rpresser@gmail.com> - 2015-08-11 12:46 -0700
  Re: Unique Constraint Based on Dual GUID --CELKO-- <jcelko212@earthlink.net> - 2015-08-11 15:30 -0700
    Re: Unique Constraint Based on Dual GUID rpresser <rpresser@gmail.com> - 2015-08-11 20:13 -0700
  Re: Unique Constraint Based on Dual GUID --CELKO-- <jcelko212@earthlink.net> - 2015-08-12 18:26 -0700
    Re: Unique Constraint Based on Dual GUID Michael Cole <invalid@invalid.com> - 2015-08-13 11:59 +1000

csiph-web