Question

I have long gene sequence which could be the natural primary key, but I'm looking for a way to find a more succinct alternative representation of the natural key. Do not want to use a surrogate key. Not worried about performance, since there will not be a lot of joins to worry about where the efficiency of the PK is an issue.

Is this possible?

        create table foo(
           myvalue varchar(2000) not null,
           md5 as hashbytes('MD5',myvalue) PERSISTED   PRIMARY KEY  NOT NULL   -- bad syntax
         )

If so, what's the correct syntax? The above is not correct.

Also can I create a child table and set up an FK relationship? I do not find the Limitations section in the documentation clear about this:

          create table fooChild(
          id int primary key not null,
          md5 varbinary(16)
           )

         alter table fooChild add constraint FK_FOOCHILD_FOO
         foreign key(md5) references FOO(md5)
Était-ce utile?

La solution

Here is the answer. http://www.devx.com/tips/Tip/15397

Basically you have to ensure a function cannot return null so wrap hashbytes in isnull or coalesce.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top