trouble with using bigint as primary key in creating table

G. Gunn - fs 146 Reputation points
2021-09-22T05:33:37.99+00:00

got the message

Warning! The maximum key length is 900 bytes. The index 'UQ__Transact__396D246F48ECC9B6' has maximum length of 1024 bytes. For some combination of large values, the insert/update operation will fail.

On trying to create a table:

>

     CREATE TABLE "dbO"."Transaction_doc" (
     "tx_doc_Id" bigint NOT NULL UNIQUE,--DEFAULT AUTOINCREMENT, 
     "subAcct_ID" INTEGER NULL,
     "acct_id" INTEGER NULL,
     "Count" SMALLINT NOT NULL DEFAULT 1,
     "processed" SMALLINT NOT NULL DEFAULT 0,
     "fileSpec" VARCHAR(1024) NOT NULL UNIQUE,
     "Updated" TIMESTAMP NULL,
     "Updated_By" VARCHAR(30) NULL,
     CONSTRAINT "PK_Transaction_Doc_tx_doc_id" PRIMARY KEY ( "tx_doc_Id" ASC )

)

what have I done to trigger the message?

PS I thought bigint is only 8 bytes and Sqlanywhere does not have trouble with this.)

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,555 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Olaf Helper 40,901 Reputation points
    2021-09-22T05:41:35.427+00:00

    The index 'UQ_Transact_396D246F48ECC9B6' has maximum length of 1024 bytes

    And how is that index defined? Does it may have the column "fileSpec" = 1.024 bytes length?


  2. EchoLiu-MSFT 14,571 Reputation points
    2021-09-22T05:53:20.563+00:00

    Please refer to:

    https://www.ibm.com/support/pages/maximum-key-length-900-bytes-index-eidunq-has-maximum-length-2000-bytes

    I also found a similar problem. Someone gave a solution to index large columns:
    Warning! The maximum key length is 900 bytes. The index has maximum length of 1000 bytes

    If you have any question, please feel free to let me know.

    Regards
    Echo


    If the answer is helpful, please click "Accept Answer" and upvote it.

    0 comments No comments

  3. Tom Cooper 8,466 Reputation points
    2021-09-22T06:59:13.69+00:00

    Before SQL 16 the maximum combined length of the columns in an index was 900 bytes. With SQL 2016, that is still the maximum length for clustered indexes, but the maximum length for nonclustered indexes is 1700 bytes. Since the unique index you defined on filespec would be a nonclustered index, you should be fine with SQL 2016 or later.

    Also, you don't want to make tx_doc_id the primary key and also declare it to be unique. Doing that will create two indexes on tx_doc_id (one clustered and one nonclustered). So you want to remove the UNIQUE attribute from tx_doc_id. Since it is the only key in your primary key constraint, it is already forced to be unique.

    Tom

    0 comments No comments