Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > microsoft.public.sqlserver.programming > #31269
| Newsgroups | microsoft.public.sqlserver.programming |
|---|---|
| Date | 2015-08-11 12:46 -0700 |
| References | <mqbsbp$9va$1@dont-email.me> |
| Message-ID | <6516db0e-cb01-4b62-99fa-c304a5ee9787@googlegroups.com> (permalink) |
| Subject | Re: Unique Constraint Based on Dual GUID |
| From | rpresser <rpresser@gmail.com> |
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 | Next — Previous in thread | Next in thread | Find similar
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