none
Using symbols in primary key RRS feed

  • Question

  • Hi All,

    I started to working on a project. I dont have a lot experiences except basic information. I just want to ask can I use symbols in primary key column like 2015/1234 etc. for file numbers. These are file numbers and must be unique so i decided to make them primary keys but im not sure that i can use symbols. thanks from now.

    Saturday, July 25, 2015 8:35 AM

Answers

  • The primary key column contents don't matter as long as it unique and not null and under the max key size (900 bytes are less).  A natural "file number" key can be used as primary key within those restrictions.  It is the underlying data type that will determine the domain of data that can be stored.

    If you choose to introduce a surrogate primary key anyway (e.g. identity column), it would be best to create a unique constraint on the file number to ensure uniqueness.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, July 25, 2015 11:38 AM
    Moderator

All replies

  • The primary key column contents don't matter as long as it unique and not null and under the max key size (900 bytes are less).  A natural "file number" key can be used as primary key within those restrictions.  It is the underlying data type that will determine the domain of data that can be stored.

    If you choose to introduce a surrogate primary key anyway (e.g. identity column), it would be best to create a unique constraint on the file number to ensure uniqueness.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, July 25, 2015 11:38 AM
    Moderator
  • We think you need to improve the concept of Primary key

    What is a key, and why is one of them a primary key?


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/

    Monday, August 3, 2015 4:02 AM