You must Sign In to post a response.
  • Category: SQL Server

    How to Set Column as Hexa Decimal

    Hi How to set primary key column as hexadecimal while designing the table in sql server.


    thanks
    thyaga
  • #768574
    Hi,

    We can create like other data types. But usually Hexadecimal wont be set a primary key because primary key are considered to be an index so when you want to search in a quick manner we go for searching the primary key in the where condition, but when the primary key was an hexadecimal it is hard to remember and hard to put in a where condition.


    CREATE TABLE yourtable(
    ComputedHexColumn AS CONVERT(VARBINARY(8), ID),
    col1 varchar(20) not null,
    col2 varchar(20) not null,
    CONSTRAINT pk_yourtablePRIMARY KEY CLUSTERED(ComputedHexColumn )
    )

    Thanks,
    Mani


Sign In to post your comments